嗨,我正在尝试创建一个完美尺寸的图像的html弹出窗口,但它只能第二次工作。
例如,当您单击图像时,它将打开时没有完美的大小,如果您关闭它并再次打开它,它就可以工作!请调试我的代码:
$(function() {
$("a.popup3").click(function(){
var asrc = $(this).attr("href");
var image = new Image();
image.src = asrc;
window.open(image.src,"Image","width="+image.width+",height="+image.height);
alert(image.src+"adfaSDF"+image.width);
return false;
});
});
,html就像:
<a class="popup3" href="http://localhost/wp/wp-content/uploads/2014/12/Eccles_leaving.jpg">
<img class="alignnone wp-image-196" src="http://localhost/wp/wp-content/uploads/2014/12/Eccles_leaving-300x200.jpg" alt="Eccles_leaving" width="220" height="147">
</a>
答案 0 :(得分:2)
尝试打开加载函数内的窗口
$(function() {
$("a.popup3").click(function(){
var asrc = $(this).attr("href");
var image = new Image();
image.src = asrc;
image.onload = function() {
window.open(image.src,"Image","width="+image.width+",height="+image.height);
};
return false;
});
});