gpt4 book ai didi

jquery - 使用 JQuery 粘性/跟随侧边栏但框标题图像不随文本移动?

转载 作者:太空宇宙 更新时间:2023-11-04 15:42:19 26 4
gpt4 key购买 nike

提前,谢谢。

我一直在使用来自 HERE 的粘性侧边栏代码并且我通过向框中添加图像标题来自定义样式,但是当它到位时它不会跟随您可以在这里看到的文本:thomas-dixon.com/joomla .

这是我使用的代码:

[view-source:http://thomas-dixon.com/joomla/][3]

感谢您的帮助。

最佳答案

演示:http://jsfiddle.net/enve/hjeBP/

将您的 jQuery 代码替换为:

<script type="text/javascript">
$(function(){ // document ready

if (!!$('#sidebar-left-content').length) { // make sure "#sidebar-left-content" element exists

var el = $('#sidebar-left-wrap');
var stickyTop = $('#sidebar-left-content').offset().top; // returns number
var footerTop = $('#footer').offset().top; // returns number
var stickyHeight = $('#sidebar-left-content').height();
var limit = footerTop - stickyHeight - 20;

$(window).scroll(function(){ // scroll event

var windowTop = $(window).scrollTop(); // returns number

if (stickyTop < windowTop){
el.css({ position: 'fixed', top: 0 });
}
else {
el.css('position','static');
}

if (limit < windowTop) {
var diff = limit - windowTop;
el.css({top: diff});
}

});

}
});</script>

工作演示:http://jsfiddle.net/enve/hjeBP/

关于jquery - 使用 JQuery 粘性/跟随侧边栏但框标题图像不随文本移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12009717/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com