1. 程式人生 > >滾動條事件window.onscroll

滾動條事件window.onscroll

 

 

 

 

例:統戰滾動條位置隨高度變化

 // 答題卡位置隨滾動條變化
      window.onscroll = function(){
        var a = document.documentElement.scrollTop || document.body.scrollTop;//滾動條y軸上的距離
        var b = document.documentElement.clientHeight || document.body.clientHeight;//可視區域的高度
        var c = document.documentElement.scrollHeight || document.body.scrollHeight;//
視覺化的高度與溢位的距離(總高度) var abc = $('.stb-content-test').offset().top; // 若滾動高度大於 if(abc >= a){ $('.stb-content-answer-div').css('top', aaa - a + 'px') } else{ $('.stb-content-answer-div').css('top','0') } }