最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JS實(shí)現(xiàn)拖動(dòng)模糊框特效

 更新時(shí)間:2020年08月25日 08:53:22   作者:hthththtt  
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)拖動(dòng)模糊框特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了JS實(shí)現(xiàn)拖動(dòng)模糊框特效的具體代碼,供大家參考,具體內(nèi)容如下

需求:

在圖片上拖動(dòng)按鈕,圖片蒙層慢慢覆蓋,當(dāng)蒙層邊緣碰到左右下角文字時(shí),文字隱藏。

技術(shù):

監(jiān)聽器,鼠標(biāo)坐標(biāo)獲取

效果圖

源碼分享:

HTML

<h1>Image Comparison Slider</h1>
 <nav>
<!--底層圖--> <img src="img/img-original.jpg" alt=""> 
<!--蒙版使用背景圖--> <div id="img">
   <h3 id="leftBottom">Modified</h3>
<!--拖動(dòng)按鈕--> <button id="btn">
    <span class="iconfont icon-zuojiantou"></span>
    <span class="iconfont icon-youjiantou"></span>
   </button>
  </div>
  <h3 id="rightBottom">Original</h3>
</nav>

CSS樣式

<style>
  * {
   margin: 0;
   padding: 0;
   color: #E8F6F5;
  }
  body {
   background-color: #566B89;
   padding-top: 1px;
  }
  nav {
   width: 1200px;
   height: 675px;
   overflow-x: hidden;
   position: relative;
   margin: 100px auto 0;
  }
  h1 {
   text-align: center;
   margin-top: 100px;
   font-weight: 400;
  }
  nav>img {
   position: absolute;
  }
  #img {
   width: 600px; /*初始狀態(tài)顯示一半蒙層*/
   height: 675px;
   background: url("img/img-modified.jpg"); /*這里容器大小與圖片一致,若想改變大小,設(shè)置背景大小屬性 background-size: 圖片寬 圖片高;*/
   position: relative;
   animation: start 1s ease-in-out;
  }
  #img img {
   width: 100%;
   height: 100%;
  }
  @keyframes start {
   0% {
    width: 0;
   }
   50% {
    width: 650px;
   }
   100% {
    width: 600px;
   }
  }
  #btn {
   position: absolute;
   right: -25px;
   top: calc(50% - 25px);
   width: 56px;
   height: 56px;
   line-height: 56px;
   border: none;
   outline: none;
   border-radius: 50%;
   background-color: pink;
   font-size: 0;
   text-align: center;
   color: white;
   cursor: pointer;
  }
  .iconfont {
   font-size: 20px;
  }

  h3 {
   font-weight: 400;
   color: white;
  }
  #leftBottom,#rightBottom {
   position: absolute;
   width: 100px;
   bottom: 50px;
  }
  #leftBottom {
   left: 50px;
  }
  #rightBottom {
   right: 50px;
  }
</style>

JS部分

<script>
  let img = document.querySelector("#img");
  let btn = document.querySelector("#btn");
  let nav = document.querySelector("nav");
  let leftBottom = document.querySelector("#leftBottom");
  let rightBottom = document.querySelector("#rightBottom");
  btn.onmousedown = function (e) {
   let clientx = e.clientX; // 點(diǎn)擊獲取鼠標(biāo)初始X坐標(biāo)
   nav.onmousemove = function () {
    let e = arguments[0] || window.event;
    let X = e.clientX; // 移動(dòng)時(shí)獲取鼠標(biāo)移動(dòng)時(shí)的X坐標(biāo)
    let imgW = parseInt(getComputedStyle(img,null).width);
    img.style.width = `${ imgW + X - clientx}px`; // 圖片寬度 = 移動(dòng)時(shí)的X坐標(biāo) - 點(diǎn)擊時(shí)的初始坐標(biāo) 也就是 圖片寬度 + 鼠標(biāo)X坐標(biāo)的偏移量
    clientx = X ; // 將最新的位置的X坐標(biāo) 賦值給 點(diǎn)擊初始坐標(biāo) 也就是 更新 X坐標(biāo)初始值
    if (imgW < 150){
     leftBottom.style.display = "none";
    }else {
     leftBottom.style.display = "block";
    }
    if (imgW > 1050){
     rightBottom.style.display = "none";
    }else {
     rightBottom.style.display = "block";
    }
   }
  };
  document.onmouseup = function () {
   nav.onmousemove = null;
  }
</script>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

  • Javascript編程之繼承實(shí)例匯總

    Javascript編程之繼承實(shí)例匯總

    這篇文章主要介紹了Javascript編程之繼承實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析匯總了五種常見的繼承技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-11-11
  • bootstrap表單示例代碼分享

    bootstrap表單示例代碼分享

    這篇文章主要為大家詳細(xì)介紹了bootstrap表單示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • JavaScript實(shí)現(xiàn)前端飛機(jī)大戰(zhàn)小游戲

    JavaScript實(shí)現(xiàn)前端飛機(jī)大戰(zhàn)小游戲

    這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)前端飛機(jī)大戰(zhàn)小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 詳解JavaScript基于面向?qū)ο笾^承實(shí)例

    詳解JavaScript基于面向?qū)ο笾^承實(shí)例

    這篇文章主要介紹了JavaScript基于面向?qū)ο笾^承實(shí)例,需要的朋友可以參考下
    2015-12-12
  • JS 實(shí)現(xiàn)Base64編碼與解碼實(shí)例詳解

    JS 實(shí)現(xiàn)Base64編碼與解碼實(shí)例詳解

    這篇文章主要介紹了JS 實(shí)現(xiàn)Base64編碼與解碼實(shí)例詳解的相關(guān)資料,并附實(shí)例代碼,幫助大家學(xué)習(xí)理解此部分知識(shí),需要的朋友可以參考下
    2016-11-11
  • JavaScript插件化開發(fā)教程(五)

    JavaScript插件化開發(fā)教程(五)

    這篇文章是JavaScript插件化開發(fā)系列教程的第五篇,還是著重于實(shí)戰(zhàn),通過具體的實(shí)例來學(xué)習(xí)jQuery的方式如何開發(fā)插件,有相同需求的小伙伴來參考下吧。
    2015-02-02
  • 利用js制作html table分頁示例(js實(shí)現(xiàn)分頁)

    利用js制作html table分頁示例(js實(shí)現(xiàn)分頁)

    這篇文章主要介紹了利用js制作html table的分頁示例(js實(shí)現(xiàn)分頁),需要的朋友可以參考下
    2014-04-04
  • js實(shí)現(xiàn)鍵盤自動(dòng)打字效果

    js實(shí)現(xiàn)鍵盤自動(dòng)打字效果

    本文主要介紹了基于jQuery實(shí)現(xiàn)的簡(jiǎn)單版鍵盤自動(dòng)打字效果,具有很好的參考價(jià)值,下面就跟著小編一起來看下吧
    2016-12-12
  • 給before和after偽元素設(shè)置js效果的方法

    給before和after偽元素設(shè)置js效果的方法

    本文通過實(shí)例給大家介紹給before和after偽元素設(shè)置js效果的方法,對(duì)js偽元素相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • 最新評(píng)論

    尖扎县| 元阳县| 柳江县| 舞阳县| 连云港市| 湾仔区| 桐庐县| 介休市| 三门县| 会理县| 洛川县| 岚皋县| 通道| 广平县| 榕江县| 革吉县| 张北县| 富川| 苍溪县| 永福县| 广灵县| 深州市| 阿尔山市| 长武县| 福清市| 怀仁县| 广汉市| 越西县| 论坛| 庄浪县| 桂平市| 饶河县| 清河县| 清水河县| 邹城市| 义乌市| 玛沁县| 武川县| 平凉市| 曲水县| 苏尼特右旗|