当我按下小缩略图时,我想显示一个大图像。一个简单的灯箱样式脚本。Javascript jQuery只在IE中显示一次Image元素。 FF工作
当我按下图像周围的灰色透明覆盖区域时,CSS和图像将从视图中移除。此代码已被删除。也许错过了需要的东西...
$(document).ready(function() {
$(".lightBobo").click(function(e) {
e.preventDefault(); // prevent to open link in new window
$(this).lightBobo();
});
});
jQuery.fn.lightBobo = function(e) {
if (e != undefined)
e.preventDefault();
return this.each(function() {
var img = new Image();
$(img).load(function() {
imgW = img.width;
imgH = img.height;
var overlay = $("<div />");
var container = $("<div />");
// Lots of css styling for <div> overlay and container image...
container.append(img); //add image to div
$("body").append(overlay); //add overlay to body
$("body").append(container); //add div to body
overlay.fadeIn("fast", function() {
container.show();
});
$(overlay).click(function() {
removeDivs();
});
function removeDivs() {
container.hide();
overlay.fadeOut("fast");
img = null;
container = null;
overlay = null;
openImgSrc = "";
}
});
});
}
问题是IE(7)没有显示图像第二次我想要显示它。我必须做一个页面重新加载才能再次显示图像。它虽然工作在FF。
当我使用FireFox时,我可以在FireBug中看到每次显示大图像时都会附加到后面。 “旧”图像显示:无; 20次后,我展示了大图,我有40个元素的覆盖和容器(图片)。
我不知道如何在需要时重新运行lightBobo函数。所以它在IE和FF都有效。
你介意添加所有必要的代码到http://jsfiddle.net/,以便它更容易调试? – aolde 2010-07-29 12:16:01