向下滚动并再次向上滚动后,灯箱顶部边距发生变化
我正在使用灯箱来显示带照片的评论。问题是,当我向下滚动查看灯箱并滚动回顶部时,即使在指定顶部后,上边距也会发生变化。
我指定顶部和左侧的 jQuery 代码是:
jQuery.fn.center = function() {
this.css("position","fixed");
var top = "20px";
left = ( $(window).width() - this.width() ) / 2+$(window).scrollLeft()+"px";
this.animate({top: top, left: left});
return this;
}
$('#tp-lightboxactitem').center();
这是灯箱 div 的 HTML:
<div class="dark-lightbox lightboxitem tp-lightboxactitem-loaded" id="tp-lightboxactitem" style="display: block; top: 20px; left: 314.5px; position: fixed; margin-top: 30px;">
<div>
<center>
<img src="uploads/_DSC9322_watcopy_bor_5_$1$uh2.fw5.$uFln.yw5QjSgVKjmhD8.jpg?id=3&pic=113" class="tp-mainimage" id="plzxc">
</center>
</div>
<div class="dark-lightbox infofield">
<div class="dark-lightbox title"></div>
<div class="dark-lightbox pageofformat">( 1 / 5 )</div>
<div class="dark-lightbox description" id="dark-lightbox description">
滚动前如何显示
![滚动前如何显示][1]
滚动后如何显示向下然后再向上
![向下然后向上滚动后的样子][2]
I'm using a lightbox to display comments with photo. The problem is that when I scroll down to see the lightbox, and scroll back to the top, the top margin changes even after specifying the top.
My jQuery code to specify top and left is :
jQuery.fn.center = function() {
this.css("position","fixed");
var top = "20px";
left = ( $(window).width() - this.width() ) / 2+$(window).scrollLeft()+"px";
this.animate({top: top, left: left});
return this;
}
$('#tp-lightboxactitem').center();
Here is the HTML for the lightbox div:
<div class="dark-lightbox lightboxitem tp-lightboxactitem-loaded" id="tp-lightboxactitem" style="display: block; top: 20px; left: 314.5px; position: fixed; margin-top: 30px;">
<div>
<center>
<img src="uploads/_DSC9322_watcopy_bor_5_$1$uh2.fw5.$uFln.yw5QjSgVKjmhD8.jpg?id=3&pic=113" class="tp-mainimage" id="plzxc">
</center>
</div>
<div class="dark-lightbox infofield">
<div class="dark-lightbox title"></div>
<div class="dark-lightbox pageofformat">( 1 / 5 )</div>
<div class="dark-lightbox description" id="dark-lightbox description">
How it appears before scrolling
![How it appears before scrolling][1]
How it appears after scrolling down and then up again
![How it appears after scrolling down and then up again][2]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过做一些小的改变来解决这个问题,
这里是代码,希望它能帮助有需要的人
Got this fixed by doing small changes
here is the code hope it helps some one in need
尝试使用这样的东西。希望它能解决它。
Try using something like this. Hope it resolves it.