码迷,mamicode.com
首页 > Web开发 > 详细

jquery scroll事件

时间:2015-03-06 16:12:12      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>scroll Demo</title>
    
    <style>
        body
        {
            margin:0px;
            padding:0px;
            height:900px;
        }
        #tip
        {
            position:absolute;
            right:0px;
            width:200px;
            height:200px;
            border:1px solid red;
        }
    </style>

    <script src="../js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
          
             var tipObj = $("#tip");
       
             var tipHeight = tipObj.height();
             
             //可视化高度 
             var clientHeight = $(window).height();
             
             var height = clientHeight-tipHeight;
             
             //window scroll事件
             $(window).scroll(function(){
                //alert("window scroll事件!!!");
             
                var scrollTop = $(this).scrollTop();
                
                var currentHeight = (height + scrollTop)/2;
                
                tipObj.css("top",currentHeight+"px");
                
             }).trigger("scroll");

            
        });
    </script>
    
</head>
<body>
 
 <div id="tip">
 
 </div>
</body>
</html>

 w3c scroll事件:

http://www.w3school.com.cn/tiy/t.asp?f=jquery_event_scroll

jquery scroll事件

标签:

原文地址:http://www.cnblogs.com/zoro-zero/p/4318380.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!