| function imgLoad(obj, width, height) { | |
| //定义要限制的图片宽高,这个宽高要同style里面定义的相同,小于限定高宽的图片不操作 | |
| var image = $(obj); | |
| if (image.width() > width) { | |
| image.height(width / image.width() * image.height()); | |
| image.width(width); | |
| } | |
| if (image.height() > height) { | |
| image.width(height / image.height() * image.width()); | |
| image.height(height); | |
| } | |
| if (image.height() > 0 && image.height() < height) { | |
| image.css("paddingTop", (height - image.height()) / 2 + "px"); | |
| image.css("paddingBottom", (height - image.height()) / 2 + "px"); | |
| } | |
| } |
图片上下居中对齐 按比例
最新推荐文章于 2024-06-04 15:43:57 发布
本文介绍了一个用于图片加载及尺寸调整的JavaScript函数。该函数能够确保图片在加载时不会超过预设的最大宽度和高度,并在图片高度小于设定高度时进行居中处理。
3789

被折叠的 条评论
为什么被折叠?



