欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js滾輪事件 js自定義滾動(dòng)條的實(shí)現(xiàn)

 更新時(shí)間:2020年01月18日 08:34:33   作者:SSSkyCong  
這篇文章主要為大家詳細(xì)介紹了js滾輪事件,自定義滾動(dòng)條的實(shí)現(xiàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js自定義滾動(dòng)條的實(shí)現(xiàn)的具體代碼,供大家參考,具體內(nèi)容如下

描述:

自定義滾動(dòng)條的實(shí)現(xiàn)

效果:

實(shí)現(xiàn):

<!DOCTYPE html>
<html lang="">
 
<head>
 <meta charset="utf-8">
 <title></title>
 <style>
  * {margin: 0;padding: 0;}
  html,body { width: 100%;height: 100%;}
  #box { width: 100%; height: 100%; overflow: hidden;}
  /*一個(gè)個(gè)劃過去的頁面塊*/
  .ball {
   width: 100%;
   height: 500px;
   font-size:100px;
   font-weight:bold;
   color: skyblue;
   text-align: center;
   line-height:500px;
  }
 
  /*//滾動(dòng)欄*/
  #scroll {
   width: 20px; height: 96%;
   position: fixed; top: 2%; right: 5px;
   border-radius: 10px; background-color: rgba(235, 233, 233, 0.5);
   z-index: 9998; opacity: 0;
  }
 
  /*//滾動(dòng)欄上的小長條*/
  #scrollBar {
   position: absolute; z-index: 1;/*//定在上面*/
   width: 20px; height: 40px;
   border-radius: 10px;
   left: 0; top: 0; background-color: red;opacity: 0.6;
  }
 </style>
</head>
 
<body style="overflow:hidden;">
<div id="box">
 <div id="content">
  <!--//營造div色塊交替的感覺-->
  <p class="ball" style="background-color:#656565;">1</p>
  <p class="ball" style="background-color:#ffffff;">2</p>
  <p class="ball" style="background-color:#656565;">3</p>
  <p class="ball" style="background-color:#ffffff;">4</p>
  <p class="ball" style="background-color:#656565;">5</p>
  <p class="ball" style="background-color:#ffffff;">6</p>
 </div>
</div>
<div id="scroll">
 <div id="scrollBar"></div>
</div>
</body>
 
</html>
<script type="text/javascript">
 var content = document.getElementById("content");
 var box = document.getElementById("box");
 var scroll = document.getElementById("scroll");
 var scrollBar = document.getElementById("scrollBar");
 var Step = {
  value : 0,
  size : 20,
  maxVal : Math.ceil((content.offsetHeight-document.body.offsetHeight)/20),
  getCurrentVal:function(){
   return this.value;
  },
  next:function(){
   if(this.value==this.maxVal) return;
   this.value++;
  },
  pre:function(){
   if(this.value==0) return;
   this.value--;
  },
  getDistance:function(){
   return this.getCurrentVal()*this.size;
  },
  update:function(){
   this.maxVal = Math.ceil((content.offsetHeight-document.body.offsetHeight)/this.size);
  }
 }
 
 window.addEventListener("resize",function(){
  Step.update();
 });
 
 box.addEventListener("DOMMouseScroll",scrollfunc);
 box.addEventListener("mousewheel", scrollfunc);
 function scrollfunc(e){
  if(e.type=="mousewheel"){ //非FF
   e.wheelDelta<0?Step.next():Step.pre();
  } else { //FF
   e.detail>0?Step.next():Step.pre();
  }
  document.title = Step.getCurrentVal();
  box.scrollTop = Math.min(Step.getDistance(),content.offsetHeight-document.body.offsetHeight);
  //計(jì)算滾動(dòng)比例
  var percent = box.scrollTop/(content.offsetHeight-document.body.offsetHeight);
  //顯示滾動(dòng)條
  scroll.style.opacity = 100;
  //計(jì)算滾動(dòng)條的位置
  scrollBar.style.top = (scroll.offsetHeight-scrollBar.offsetHeight)*percent + "px";
 
 }
</script>

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

相關(guān)文章

  • vue雙向綁定簡要分析

    vue雙向綁定簡要分析

    這篇文章主要介紹了vue雙向綁定的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • js實(shí)現(xiàn)TAB切換對應(yīng)不同顏色的代碼

    js實(shí)現(xiàn)TAB切換對應(yīng)不同顏色的代碼

    這篇文章主要介紹了js實(shí)現(xiàn)TAB切換對應(yīng)不同顏色的代碼,涉及javascript頁面元素的遍歷及樣式的動(dòng)態(tài)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-08-08
  • 原生JS實(shí)現(xiàn)列表子元素順序反轉(zhuǎn)的方法分析

    原生JS實(shí)現(xiàn)列表子元素順序反轉(zhuǎn)的方法分析

    這篇文章主要介紹了原生JS實(shí)現(xiàn)列表子元素順序反轉(zhuǎn)的方法,結(jié)合實(shí)例形式分析了javascript針對dom元素、數(shù)組reverse方法、innerHTML方法等列表元素順序翻轉(zhuǎn)相關(guān)操作技巧,需要的朋友可以參考下
    2018-07-07
  • js實(shí)現(xiàn)同一頁面多個(gè)運(yùn)動(dòng)效果的方法

    js實(shí)現(xiàn)同一頁面多個(gè)運(yùn)動(dòng)效果的方法

    這篇文章主要介紹了js實(shí)現(xiàn)同一頁面多個(gè)運(yùn)動(dòng)效果的方法,涉及javascript操作頁面元素運(yùn)動(dòng)效果的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • bootstrap輪播模板使用方法詳解

    bootstrap輪播模板使用方法詳解

    這篇文章主要介紹了bootstrap輪播模板的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • JS使用Promise時(shí)常見的5個(gè)錯(cuò)誤總結(jié)

    JS使用Promise時(shí)常見的5個(gè)錯(cuò)誤總結(jié)

    Promise?提供了一種優(yōu)雅的方法來處理?JS?中的異步操作。這也是避免“回調(diào)地獄”的解決方案。然而,并沒有多少開發(fā)人員了解其中的內(nèi)容。因此,許多人在實(shí)踐中往往會(huì)犯錯(cuò)誤。在本文中,介紹一下使用?promise?時(shí)的五個(gè)常見錯(cuò)誤,希望大家能夠避免
    2022-11-11
  • JavaScript創(chuàng)建對象的幾種方式及關(guān)于this指向問題

    JavaScript創(chuàng)建對象的幾種方式及關(guān)于this指向問題

    這篇文章主要介紹了JavaScript創(chuàng)建對象的幾種方式及關(guān)于this指向問題,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值。需要的小伙伴可以參考一下
    2022-07-07
  • 最新評論