在div中滚动侧边栏

时间:2016-04-03 17:13:30

标签: javascript html css scroll sidebar

我希望我的社交侧边栏仅在灰色div中滚动。我已经把侧边栏放在灰色div内,不超过页脚或上面的内容。我的难点在于伴随滚动的侧边栏滚动而不是灰色div。

beautyAcademy.sharer = {
element: void 0,
elementToScroll: void 0,
init:function() {
    this.element = $('.js-sharer-ref');
    console.log(this.element.length);
    if(this.element.length != 1) {
        return;
    }
    this.build();
},
build: function() {
    this.binds();
},
binds: function() {
    var _this = this;

    // FIXED SOCIAL

    // Element that's gonna scroll
    this.$elementToScroll = $('.fixed-social');

    this.$elementTop = this.$elementToScroll.offset().top;

    // Element that's gonna scroll height
    this.elementToScrollHeight = this.$elementToScroll.outerHeight();


    // JS SHARER REF

    // Element where scroll is gonna happen Height
    this.elementHeight = this.element.outerHeight();

    // Element where scroll is gonna happen distance to top
    this.elementOffsetTop = this.element.offset().top;

    // Scroll that was done on the page
    this.windowScrollTop = $(window).scrollTop();

    this.elementOffsetBottom = this.elementOffsetTop + this.elementHeight - this.elementToScrollHeight;

    this.$elementToScroll.css('top', (_this.elementOffsetTop+80) + "px");

    $(window).on('scroll', function() {

    });
}
};

0 个答案:

没有答案