大佬教程收集整理的这篇文章主要介绍了jquery – 拉伸图像以填充div,但不倾斜,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我要问的是某种简单的jQuery函数,它调整图像的大小以完全填充隐藏溢出的div,这样就没有间隙,但不会使图像偏斜.
编辑:
这就是我所追求的,但我希望图像能够填满整个div,而不会产生偏差.如果图像有点偏离div,那很好,但是我需要用div来调整大小,div会调整页面的高度和宽度.
//this would load up initially,you will need this data for future processing div = $("div"); imgsrc = div.find('img').attr('src'); var img = new Image() img.onload = function(){ imgw = img.width; imgh = img.height; //after its loaded and you got the size.. //you need to call it the first time of course here and make it visible: resizeMyImg(imgw,imgh); div.find('img').show(); //Now you can use your resize function $(window).resize(function(){ resizeMyImg(imgw,imgh) }); } img.src = imgsrc function resizeMyImg(w,h){ //the width is larger if (w > h) { //resize the image to the div div.find('img').width(div.innerWidth() + 'px').height('auto'); } else { // the height is larger or the same //resize the image to the div div.find('img').height(div.innerHeight() + 'px').width('auto'); } }
您可以在这里找到完整的解决方案:
http://jsfiddle.net/CDywS/1
以上是大佬教程为你收集整理的jquery – 拉伸图像以填充div,但不倾斜全部内容,希望文章能够帮你解决jquery – 拉伸图像以填充div,但不倾斜所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。