>  기사  >  웹 프론트엔드  >  동일한 스케일링 이미지 효과를 얻으려면 jquery를 사용하십시오.

동일한 스케일링 이미지 효과를 얻으려면 jquery를 사용하십시오.

WBOY
WBOY원래의
2016-05-16 18:22:311481검색
复代码码 代码如下:

jQuery.fn.autoZoomLoadImage = 함수(크기 조정, 너비, 높이, loadPic ) {
if (loadPic == null) loadPic = "Loading.gif";
return this.each(function() {
var t = $(this);
var src = $(this).attr("src");
var img = new Image( );
//alert("Loading")
img.src = src;
//自动缩放图文
var autoScaling = function() {
if (scaling) {
if (img.width > 0 && img.height > 0) {
if (img.width / img.height >= 너비 / 높이) {
if (img.width > width) {
t.width(너비);
t.height((img.height * 너비) / img.width)
}
else {
t.width(img.width) );
t.height(img.height);
}
}
else {
if (img.height > height) {
t.height(height);
t.width((img.width * height) / img.height);
}
else {
t.width(img.width)
t.height(img. 높이)
}
}
}
}
}
//处理ff下会自动读取缓存图文
if (img.complete) {
//alert("getToCache!");
autoScaling();
return;
}
$(this).attr("src", ""); $("加载中")
t.hide()
t.after(loading) ;
$(img).load(function() {
autoScaling();
loading.remove();
t.attr("src", this.src);
t.show();
//alert("드디어!")
});
});
}

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.