简体   繁体   English

页面加载时滚动侧栏位置

[英]Scrolling sidebar position on page load

How can I make my scrolling sidebar set its correct position on document ready without an animation? 如何在没有动画的情况下使滚动侧栏在文档上设置正确的位置? Keep in mind, I want to keep the animation for general scrolling after page load. 请记住,我想让动画在页面加载后进行常规滚动。

I used .scroll() to trigger a scroll on load but this looks sloppy when halfway down a page and you're waiting for the sidebar to catch up. 我使用了.scroll()来触发加载时的滚动,但是在页面的一半向下时这看起来很草率,并且您正在等待侧边栏的赶上。

http://jsfiddle.net/b4MaJ/1/ http://jsfiddle.net/b4MaJ/1/

w.scroll(function () {
    if (w.scrollTop() > offset.top) {
        sidebar.stop().animate({
            marginTop: w.scrollTop() - offset.top + 45
        }, function () {
            distance = (footer.offset().top - footer.outerHeight()) - sidebar.offset().top;
            if (distance <= 50) {
                sidebar.stop().animate({
                    opacity: 0
                }, 250);
            } else {
                sidebar.stop().animate({
                    opacity: 1
                }, 250);
            }
        });
    } else {
        sidebar.stop().animate({
            marginTop: 0
        });
    }
}).scroll();

use position:fixed; 使用position:fixed; in .customerOrder .customerOrder

DEMO 演示

.customerOrder {
    background: red;
    position:fixed;
    top:30px;
    right:5px;
}

Remove Jquery 删除jQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM