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

JS實現(xiàn)拖動模糊框特效

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

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

需求:

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

技術(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>
<!--拖動按鈕--> <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; // 點擊獲取鼠標(biāo)初始X坐標(biāo)
   nav.onmousemove = function () {
    let e = arguments[0] || window.event;
    let X = e.clientX; // 移動時獲取鼠標(biāo)移動時的X坐標(biāo)
    let imgW = parseInt(getComputedStyle(img,null).width);
    img.style.width = `${ imgW + X - clientx}px`; // 圖片寬度 = 移動時的X坐標(biāo) - 點擊時的初始坐標(biāo) 也就是 圖片寬度 + 鼠標(biāo)X坐標(biāo)的偏移量
    clientx = X ; // 將最新的位置的X坐標(biāo) 賦值給 點擊初始坐標(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>

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

  • Javascript編程之繼承實例匯總

    Javascript編程之繼承實例匯總

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

    bootstrap表單示例代碼分享

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

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

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

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

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

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

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

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

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

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

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

    js實現(xiàn)鍵盤自動打字效果

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

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

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

    定西市| 庄河市| 武冈市| 名山县| 曲沃县| 辰溪县| 东莞市| 册亨县| 酒泉市| 曲靖市| 鱼台县| 上栗县| 绥中县| 福建省| 宜君县| 松原市| 山西省| 化德县| 内江市| 长沙市| 彭水| 梁河县| 通海县| 昌邑市| 罗甸县| 如东县| 福海县| 张家口市| 饶河县| 仁化县| 蒲江县| 虞城县| 黄骅市| 阳原县| 五家渠市| 涟源市| 彰化县| 富源县| 泸定县| 合川市| 咸阳市|