右边窗口随动

原创
2015/02/06 15:33
阅读数 47
<script type="text/javascript">
  // 右边窗口随动
  function fixedSidebar() {
    var side = $('.sidebar');
    var sideTop = side.offset().top + side.height();
    var h = $('.main').height() - side.height();
    var timer = 300;
    var fixStatus = function() {
        var winHeight = $(window).height();
        var scrollTop = $(document).scrollTop();
        var tempBottom = scrollTop + winHeight - sideTop;
        if (tempBottom > h) {
            tempBottom = h
        };
        if (scrollTop + winHeight > sideTop) {
            side.css({
                position: 'absolute',
                right: '0'
            }).stop(true).animate({
                top: tempBottom
            },
            timer)
        } else {
            side.css({
                position: 'static',
                right: '0'
            }).stop(true).animate({
                top: 0
            },
            timer)
        }
    };
    $(window).scroll(function() {
        fixStatus()
    });
    $(window).resize(function() {
        fixStatus()
    })
};
fixedSidebar();
</script>


展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部