zoukankan      html  css  js  c++  java
  • 图片大小自动缩略 显示

    function resizePic_temp(o, Mw, Mh, need_margin) {
        var _Mw = Mw || 120;
        var _Mh = Mh || 120;
        var need_resize = false;
        var _image = new Image();
        _image.src = o.src;
        function getRightWH(Rw, Rh, Mw, Mh) {
            var index = 0,
                    _Rw = Rw,
                    _Rh = Rh;
            if (Rw > Mw) index += 1;
            if (Rh > Mh) index += 2;
            switch (index) {
                case 1:
                    _Rw = Mw;
                    _Rw = Rh * Mw / Rw;
                case 2:
                    _Rh = Mh;
                    _Rw = Rw * Mh / Rh;
                case 3:
                    _Rh = (Rh / Mh > Rw / Mw) ? Mh : Rh * Mw / Rw;
                    _Rw = (Rh / Mh > Rw / Mw) ? Rw * Mh / Rh : Mw
            }
            if (index != 0) {
                need_resize = true;
            }
            return [_Rw, _Rh];
        }
        var wh = getRightWH(_image.width, _image.height, _Mw, _Mh);
        o.style.width = wh[0] + 'px';
        o.style.height = wh[1] + 'px';
        o.setAttribute("width", wh[0]);
        o.setAttribute("height", wh[1]);
        o.style.visibility = 'visible';
        if (need_margin == true) {
            o.style.marginTop = (Mh - parseInt(wh[1])) / 2 + 'px'
        }
        _image = null;
        return need_resize;
    }
    
  • 相关阅读:
    二极管测试
    MOS开关速度
    STM8L PWM输出通道
    STM8Lpwm
    IAR 使用技巧
    java学习第十一天
    java学习第十天
    java学习第九天
    部分总结
    发现一篇好文,说的很详细,先收藏了。
  • 原文地址:https://www.cnblogs.com/nanxiaoxiang/p/2944780.html
Copyright © 2011-2022 走看看