网页滚动事件,触发是指定元素的位置改变

//网页滚动事件,触发是指定元素的位置改变
<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>
 

你可能感兴趣的:(JavaScript,chrome)