向下滚动时,Jquery滚动到固定定位

时间:2015-01-08 11:37:24

标签: javascript jquery css

我有一个关于我的滚动到固定jquery插件的问题。

我是从 codepen.io

创建的 DEMO

你可以在这个演示中看到当你向下滚动然后修复了头像图像但是如果你向上滚动问题就在那里.text div位置。我怎么能修理它,任何人都可以帮助我?

1 个答案:

答案 0 :(得分:0)

在附带的jQuery中有一个方法" setFixed()"将位置设置为position =' fixed&#39 ;;将其更改为position =' relative'

实际功能

function setFixed() {
        // Only fix the target element and the spacer if we need to.
        if (!isFixed()) {
            // Set the spacer to fill the height and width of the target
            // element, then display it.
            spacer.css({
                'display' : target.css('display'),
                'width' : target.outerWidth(true),
                'height' : target.outerHeight(true),
                'float' : target.css('float')
            });

            // Set the target element to fixed and set its width so it does
            // not fill the rest of the page horizontally. Also, set its top
            // to the margin top specified in the options.

            cssOptions={
                'z-index' : base.options.zIndex,
                'position' : 'relative',
                'top' : base.options.bottom == -1?getMarginTop():'',
                'bottom' : base.options.bottom == -1?'':base.options.bottom,
                'margin-left' : '0px'
            }
            if (!base.options.dontSetWidth){ cssOptions['width']=target.css('width'); };

            target.css(cssOptions);

            target.addClass(base.options.baseClassName);

            if (base.options.className) {
                target.addClass(base.options.className);
            }

            position = 'fixed';
        }
    }

更改为

function setFixed() {
        // Only fix the target element and the spacer if we need to.
        if (!isFixed()) {
            // Set the spacer to fill the height and width of the target
            // element, then display it.
            spacer.css({
                'display' : target.css('display'),
                'width' : target.outerWidth(true),
                'height' : target.outerHeight(true),
                'float' : target.css('float')
            });

            // Set the target element to fixed and set its width so it does
            // not fill the rest of the page horizontally. Also, set its top
            // to the margin top specified in the options.

            cssOptions={
                'z-index' : base.options.zIndex,
                'position' : 'relative',
                'top' : base.options.bottom == -1?getMarginTop():'',
                'bottom' : base.options.bottom == -1?'':base.options.bottom,
                'margin-left' : '0px'
            }
            if (!base.options.dontSetWidth){ cssOptions['width']=target.css('width'); };

            target.css(cssOptions);

            target.addClass(base.options.baseClassName);

            if (base.options.className) {
                target.addClass(base.options.className);
            }

            position = 'relative';
        }
    }