【发布时间】:2014-01-11 19:28:28
【问题描述】:
我已从http://usejquery.com/blog/create-unique-gallery-using-z-index-and-jquery 修改了图库脚本,它在除 IE10 之外的所有浏览器中都能正常工作。在这里看到它:http://174.122.126.251/~arblockt/index.html。这些照片应该将顶部图像“洗牌”到堆栈底部,但在 IE10 中,顶部照片仍位于顶部。
这是修改后的脚本:
$(document).ready(function() {
var z = 0;
var inAnimation = false;
$('#pictures img').each(function() {
z++;
$(this).css('z-index', z);
});
function swapFirstLast() {
if(inAnimation) return false; //if already swapping pictures just return
else inAnimation = true; //set the flag that we process a image
$('#pictures img').each(function() { //process each image
if($(this).css('z-index') == z) { //if its the image we need to process
$(this).animate({ 'left' : '-' + $(this).width() + 'px' }, 'slow', function() { //animate the img above/under the gallery (assuming all pictures are equal height)
$(this).css('z-index', 1) //set new z-index
.animate({ 'left' : '0' }, 'slow', function() { //animate the image back to its original position
inAnimation = false; //reset the flag
});
});
} else { //not the image we need to process, only in/de-crease z-index
$(this).animate({ 'left' : '0' }, 'slow', function() { //make sure to wait swapping the z-index when image is above/under the gallery
$(this).css('z-index', parseInt($(this).css('z-index')) + 1); //in/de-crease the z-index by one
});
}
});
return false; //don't follow the clicked link
}
window.setInterval(swapFirstLast, 3000);
});
谁能明白为什么这在每个浏览器(甚至是旧版本的 IE)中都有效,但在 IE10 中无效?
提前感谢您的帮助。
更新: 它仍然无法在 IE10 中运行,但我确实注意到,如果让它继续运行一段时间,顶部图片最终会移到后面,但新的顶部图片会做同样的事情并保持在顶部。很奇怪。
更新#2: 我只是在 IE10 窗口运行时调整了它的大小,它立即开始正常工作。知道什么可能导致这种非常奇怪的行为吗?谢谢!
【问题讨论】:
-
我不知道具体原因,但我可以告诉你
<meta http-equiv="X-UA-Compatible" content="IE=9" />可能会起作用。不幸的是,这有点骇人听闻,不是直接的答案,因此它是评论 -
是的,我知道。我很绝望!尝试任何我能想到的。哈哈,我已经把它删除了。
-
我发现了问题,但我不知道为什么会这样。我删除了除脚本所需的所有 CSS 之外的所有 CSS,然后一次将其添加回 1 种样式。原来,页脚样式包括位置:相对。当我删除它时,一切正常。奇怪的是,页脚 div 在画廊的容器元素之外和之下,所以我不知道为什么这会对画廊产生影响,而且只在 IE10 中。我已经解决了这个问题,但我仍然很好奇为什么会发生这种情况。有没有人听说过这种情况并能对此有所了解?
标签: jquery z-index internet-explorer-10 photo-gallery