본문 바로가기
etc.tip

티스토리 외부이미지 리사이징

by 짤방장2 2017. 4. 21.
반응형

<script>
        function resizeImg() {
            var windowWidth = $(window).width();
            var windowHeight = $(window).height();
           
            $("#content img, .resizablebox").each(function() {
                var imgPosition = $(this).css('position');
               
                if (imgPosition == 'absolute') {
                    var imgWidth = $(this).width();
                    var imgHeight = $(this).height();
                    var wRate = windowWidth / imgWidth;
                    var hRate = windowHeight / imgHeight;
                   
                    if (wRate > hRate) {
                        var newWidth = imgWidth * hRate;
                        var newHeight = imgHeight * hRate;
                    } else {
                        var newWidth = imgWidth * wRate;
                        var newHeight = imgHeight * wRate;
                    }
                   
                    $(this).css({
                        'width':newWidth+'px',
                        'height':newHeight+'px'
                    });
                }
            });
        }
        $(function() {
            $("#content img, .resizablebox").each(function() {
                var oImgWidth = $(this).width();
                var oImgHeight = $(this).height();
                var windowWidth = $(window).width();
                var windowHeight = $(window).height();
                var imgPosition = $(this).css('position');
               
                $(this).css({
                    'max-width':oImgWidth+'px',
                    'max-height':oImgHeight+'px'
                });
               
                if (imgPosition != 'absolute') {
                    $(this).css({
                        'width':'100%',
                        'height':'100%'
                    });
                }
            });
        });
        $(window).on('resize', resizeImg);
        $(window).on('load', resizeImg);
</script>



<html></head>안에삽입

http://www.erzsamatory.net/86 참조

반응형

댓글


top
bottom