我在控制台出错:
TypeError: $("<img/>").attr("src", e.attr("src")) is undefine
$('<img/>').attr('src', e.attr('src')).load(function(){
以下是整个功能代码:
function resizeOriginalImg(element, original)
{
var e = jQuery(element);
var newWidth, newHeight, imageWidth, imageHeight, realWidth, realHeight;
$('<img/>').attr('src', e.attr('src')).load(function(){
realWidth = this.width;
realHeight = this.height;
});
if(original)
{
imageWidth = realWidth;
imageHeight = realHeight;
}
else
{
imageWidth = e.width();
imageHeight = e.height();
}
if(imageWidth > jQuery(window).width() || imageHeight > jQuery(window).height())
{
if(imageWidth >= imageHeight)
{
newWidth = jQuery(window).width();
newHeight = (newWidth/imageWidth)*imageHeight;
}
else
{
newHeight = jQuery(window).height();
newWidth = (newHeight/imageHeight)*imageWidth;
}
}
e.css({'width' : newWidth, 'height' : newHeight});
};
和
resizeOriginalImg('.current-slide .myimage', true);
我不知道那里出了什么问题,一切似乎都很好,但它不起作用。也许
$('<img/>').attr('src', e.attr('src')).load(function()
位置不好,导致错误?
提前感谢您的帮助。