图片自动缩放
时间:2011-01-18 来源:caicainiao
下面给出一个示例:
Css代码
- <style>
- .Image {
- max-width:600px;cursor:pointer;
- border:1px dashed #4E6973;padding: 3px;
- zoom:expression( function(elm) {
- if (elm.width>560) {
- var oldVW = elm.width; elm.width=560;
- elm.height = elm.height*(560 /oldVW);
- }
- elm.style.zoom = '1';
- }(this));
- }
- </style>
<style>
.Image {
max-width:600px;cursor:pointer;
border:1px dashed #4E6973;padding: 3px;
zoom:expression( function(elm) {
if (elm.width>560) {
var oldVW = elm.width; elm.width=560;
elm.height = elm.height*(560 /oldVW);
}
elm.style.zoom = '1';
}(this));
}
</style>
这里使用了expression,但是利用了一次加载,所以expression不会造成内存泄漏。
我们可以这样去用它:
Html代码
- <IMG SRC="test.jpg" WIDTH="990" HEIGHT="2000" BORDER="0" ALT="" class="Image">
<IMG SRC="test.jpg" WIDTH="990" HEIGHT="2000" BORDER="0" ALT="" class="Image">
这样,当一张图片超过指定宽度时,则会进行自动缩放显示。
相关阅读 更多 +










