调整图像功能

时间:2012-11-01 17:58:39

标签: jquery screen

我在控制台出错:

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() 

位置不好,导致错误?

提前感谢您的帮助。

0 个答案:

没有答案