JavaScript控制固定邊框,圖片所有展現

        function fiximg(wimg,maxwidth,maxheight){
            var rwidth = wimg.width;
            console.log(wimg);
            var rheight = wimg.height;
            if(rwidth<=maxwidth&&rheight<=maxheight){
                wimg.width = rwidth;
                wimg.height = rheight;
            }else {
                if(rwidth/rheight<maxwidth/maxheight){
                    wimg.height = maxheight;
                    wimg.width = wimg.width*maxheight/wimg.height;
                }else{
                    wimg.width = maxwidth;
                    wimg.height = wimg.height*maxwidth/wimg.width;
                }
            }
        }
        window.onload = function(){
            var xx = document.getElementById('cimg');
            fiximg(xx,400,400);
        }

JavaScript控制固定邊框,圖片所有展現spa

相關文章
相關標籤/搜索