zoukankan      html  css  js  c++  java
  • js 图片自适应

    onload="ResizeImage(this,220,200);

    function ResizeImage(obj, MaxW, MaxH) {

            if (obj != null) imageObject = obj;

            var state = imageObject.readyState;

            if (state != 'complete') {

                setTimeout("ResizeImage(null," + MaxW + "," + MaxH + ")", 50);

                return;

            }

            var oldImage = new Image();

            oldImage.src = imageObject.src;

            var dW = oldImage.width;

            var dH = oldImage.height;

            if (dW > MaxW || dH > MaxH) { a = dW / MaxW; b = dH / MaxH; if (b > a) a = b; dW = dW / a; dH = dH / a; }

            if (dW > 0 && dH > 0) { imageObject.width = dW; imageObject.height = dH; }

        }

    方法二

    <script>
        var imageArr=document.getElementById(controlID);
        var imageRate = imageArr.offsetWidth / imageArr.offsetHeight;   
       
        if(imageArr.offsetWidth > maxWidth)
        {
            imageArr.style.width=maxWidth + "px";
            imageArr.style.Height=maxWidth / imageRate + "px";
        }
       
        if(imageArr.offsetHeight > maxHeight)
        {
            imageArr.style.width = maxHeight * imageRate + "px";
            imageArr.style.Height = maxHeight + "px";
        }

    </script>

  • 相关阅读:
    4、springboot之全局异常捕获
    3、springboot之热部署
    可重入锁
    2、springboot返回json
    1、springboot之HelloWorld
    [转]查询 SQL Server 系统目录常见问题
    设计模式原则详解
    [转]第二章 控制反转和依赖注入
    [转]Spring.Net介绍
    [转]Oracle High Water Level高水位分析
  • 原文地址:https://www.cnblogs.com/tangself/p/1693755.html
Copyright © 2011-2022 走看看