本文的示例说明jQuery限制
图片大小的方式:
在最新的信息
网站中,文章的内容可以
显示图片,因此有必要限制
用户输入的图像显示的大小。
在因特网上找到一段代码。
$(
文档)Ready(
函数(){)
$(# viewnews_body IMG)。每个(函数(){)
var宽度= 620;
var高度= 600;
var = $(this);
如果(image.width()> image.height()){
如果(image.width()>宽度){
Image.width(宽);
image.height(宽/ image.width image.height()*());
}
其他{ }
如果(image.height()>高度){
image.height(高度);
Image.width(高/ image.height image.width()*());
}
}
});
});
该
方法操作效果不稳定,不加载时间图像,将首先
执行。
因此,它适用于所有需要有限大小的图片来绑定负载事件,这样我们可以在每次加载图片之后分别执行有限大小的代码:
$(文档)Ready(函数(){)
$(# viewnews_body IMG)Bind(负荷。
var宽度= 620;
var高度= 600;
var = $(this);
如果(image.width()> image.height()){
如果(image.width()>宽度){
Image.width(宽);
image.height(宽/ image.width image.height()*());
}
其他{ }
如果(image.height()>高度){
image.height(高度);
Image.width(高/ image.height image.width()*());
}
}
});
});
关于jQuery相关内容的更多读者感兴趣的读者可以看到这个特殊的站点:
希望本文能对jQuery
程序设计有所帮助。