图片缩放,兼容页面读取

<script type="text/javascript">
function setStyle(elem,prop,value) {
elem.style[prop] = value ;
}
function imageLoad() {
    this.style.visibility = 'hidden';
    this.style.display = 'block';
    var width = this.clientWidth;
    var height = this.clientHeight;
    this.style.display = 'none';
    this.style.visibility = 'visible';
    if(width > 180 || height > 120) {
        if(width > 180 && height > 120) {
            var min = Math.min(width,height);
            if(min == width) {
                setStyle(this,'width' , '180px');
                setStyle(this,'height',Math.floor(height * 180 / width) + 'px');
            } else {
                setStyle(this,'width' , Math.floor(width * 120 / height) + 'px');
                setStyle(this,'height','120px');
            }
        } else {
            if(width > 180) {
                setStyle(this,'width' , '180px');
                setStyle(this,'height',Math.floor(height * 180 / width) + 'px');
            } else {
                setStyle(this,'width' , Math.floor(width * 120 / height) + 'px');
                setStyle(this,'height','120px');
            }
        }
    }
    this.style.display = 'block';
    this.onload = null;
}
</script>

你可能感兴趣的:(JavaScript)