<script type="text/javascript">

      //图片自适应

        $(function () {

            var imglist = document.getElementsByTagName("img");

            // $("img").attr(&#039;style&#039;, &#039;&#039;);

            //安卓4.0+等高版本不支持window.screen.width,安卓2.3.3系统支持

            var _width;

            doDraw();

            window.onresize = function () {

                //捕捉屏幕窗口变化,始终保证图片根据屏幕宽度合理显示

                doDraw();

            }

            function doDraw() {

                _width = window.innerWidth;//屏幕宽度

                for (var i = 0, len = imglist.length; i < len; i++) {

                    DrawImage(imglist[i], _width);

                }

            }

            function DrawImage(ImgD, _width) {

                var image = new Image();

                image.src = ImgD.src;

                image.onload = function () {

                    //限制,只对宽高都大于192的图片做显示处理,换成你想要的宽度。

                    if (image.width <1920 && image.height <1920) {

                        if (image.width > _width) {

                            ImgD.style.width = "";

                            ImgD.style.height = "";

                            ImgD.width = _width/1.1;

                            ImgD.height = (image.height * _width) / image.width;

                        } else {

                            ImgD.style.width = "";

                            ImgD.style.height = "";

                            ImgD.width = image.width;

                            ImgD.height = image.height;

                        }

                    }

                }

            }

        })

</script>

THE END

本站部分文章搜集整理于互联网或者网友提供,如有侵权请联系站长

如若转载,请注明出处:https://www.htmlbk.com/dedecms/218.html

温馨提示:该文档最后一次修改时间为2019-07-26 22:35:09,请注意相关的内容是否还可用!