[英]jQuery Div Scrolling Function: Issue in IE
I'm currently developing a website that that has a fixed banner div that is centered, and I'm using the jQuery below to ensure that it scrolls correctly even though it is a fixed positioned div. 我目前正在开发一个网站,该网站的固定横幅div居中,并且我使用下面的jQuery来确保即使它是固定位置的div也能正确滚动。
jQuery: jQuery的:
$(window).scroll(function() {
$('#top-content').css('left', -$(this).scrollLeft() + "px");
});
However, I have come across an issue within IE(version 9). 但是,我在IE(版本9)中遇到了一个问题。 The issue is that when the user scrolls the website (creating a minus left margin on the "top-content" div, to give the effect of scrolling) and then if they maximize the webpage, the left margin is still present causing the div to not be centered.
问题是,当用户滚动网站时(在“顶部内容” div上创建一个负的左边距,以提供滚动效果),然后,如果他们最大化网页,则左边距仍然存在,导致div不居中。
I have attempted to remedy this with the jQuery below, but as of yet no luck 我试图用下面的jQuery来解决这个问题,但是到目前为止还没有运气
$(window).resize(function() {
if ($("#top-content").width() < $(window).width()) {
$('#top-content').css('left:0px');
}
});
Any ideas? 有任何想法吗?
You better do 你最好做
$('#top-content').css('left', '0px');
In your resize event. 在您调整大小事件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.