Javascript 向下滚动时,Jquery滚动到固定位置
我有一个关于我的滚动到固定jquery插件的问题 我从codepen.io创建了这个Javascript 向下滚动时,Jquery滚动到固定位置,javascript,jquery,css,Javascript,Jquery,Css,我有一个关于我的滚动到固定jquery插件的问题 我从codepen.io创建了这个 你可以在这个演示中看到,当你向下滚动时,阿凡达图像修复了,但是如果你向上滚动,问题就出现在.textdiv位置。我如何修复它?有人能帮我吗?在附加的jQuery中有一个方法“setFixed()”,它将位置设置为position='fixed';将其更改为position='relative' 实际功能 改为 将相关代码复制到问题上总是一个好主意。现在,如果你的代码笔被删除,没有人会从这个问题中受益。幸运的是@
你可以在这个演示中看到,当你向下滚动时,阿凡达图像修复了,但是如果你向上滚动,问题就出现在
.text
div位置。我如何修复它?有人能帮我吗?在附加的jQuery中有一个方法“setFixed()”,它将位置设置为position='fixed';将其更改为position='relative'
实际功能
改为
将相关代码复制到问题上总是一个好主意。现在,如果你的代码笔被删除,没有人会从这个问题中受益。幸运的是@mateen在他的一个答案中提供了代码,但这应该是问题的一部分。
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';
}
}