首页 > 解决方案 > 为stick_in_parent 设置新的offset_top

问题描述

我使用sticky-kitJquery 的框架来fix the sidebar. 我成功地做到了,就像那样

这个网站已经把这段代码放在了它的js部分。offset_top: 10

这个高度在向下滚动和向上滚动模式下都保持不变。它工作正常

如果您向上滚动,我想将其更改为 10 像素。如果向下滚动,距离为 0 像素

所以我写了下面的代码,但它不起作用:

            if (scroll_to_top) {
                    $("#aside").stick_in_parent({
                        offset_top: 10
                    });
            }
            if (scroll_to_down) {
                    $("#aside").stick_in_parent({
                        offset_top: 0
                    });
            }

我应该怎么办?

标签: jquerysticky

解决方案


尝试这个:

        if (scroll_to_top) {
                $("#aside").css({
                    "top": "10px"
                });

        }
        if (scroll_to_down) {
                $("#aside").css({
                    "top": "0px"
                });
        }

推荐阅读