網頁滾動事件,觸發是指定元素的位置改變

Js代碼 
//網頁滾動事件,觸發是指定元素的位置改變 
Js代碼 
<script type="text/javascript"> 
    window.onscroll = function() { 
        scrollItem(); 
    } 
 
    function scrollItem(){ 
        //alert(document.body.scrollTop); 
        if(navigator.userAgent.indexOf("Chrome")>0){ 
            document.getElementById("notice_jqm").style.top=document.body.scrollTop+(document.documentElement.clientHeight-document.getElementById("notice_jqm").offsetHeight)/2+"px"; 
            //alert(document.getElementById("winpop").style.top);document.getElementById("winpop").style.left=document.body.scrollLeft+(document.documentElement.clientWidth-document.getElementById("winpop").offsetWidth)/2+"px"; 
        } 
        else{ 
            document.getElementById("notice_jqm").style.top=document.documentElement.scrollTop+(document.documentElement.clientHeight-document.getElementById("notice_jqm").offsetHeight)/2+"px"; 
            //alert(document.getElementById("winpop").style.top);document.getElementById("winpop").style.left=document.documentElement.scrollLeft+(document.documentElement.clientWidth-document.getElementById("winpop").offsetWidth)/2+"px"; 
        } 
    } 
 
 
</script> 

作者“wolf blog”
 

You May Also Like