• 移动端 图片不变形


    @{
    Layout = null;
    }

    <!DOCTYPE html>

    <html>
    <head>
    @*<meta name="viewport" content="width =device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />*@
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />

    <title></title>
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/scrollLazy.js"></script>
    <script type="text/javascript">
    function myfun() {
    var pId = GetQueryString("productId");
    $.ajax({
    type: "POST",
    url: "/DisplayDetailImages/GetDetailImages",
    data: { productId: pId },
    datatype: "html",
    success: function (data) {
    if (data == "") {
    alert("暂无详情!!");
    }
    var html = "";
    html += "<p>"
    var imgsplit = data.split(',');
    for (var i = 0; i < imgsplit.length - 1; i++) {
    html += imgsplit[i];
    }
    html += "</p>"
    $(".details_bottom").html('');
    $(".details_bottom").html(html);

    for (var i = 0; i < imgsplit.length - 1; i++) {
    $("img").eq(i).attr('data-src', $("img").eq(i).attr('src'));
    $("img").eq(i).attr('src', 'xxxx');
    }
    new LazyScroll({ 'wrapId': 'body' });
    var imglist = document.getElementsByTagName("img");
    //安卓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 () {
    //限制,只对宽高都大于30的图片做显示处理,换成你想要的宽度。
    if (image.width > 30 && image.height > 30) {
    if (image.width > _width) {
    ImgD.width = _width;
    ImgD.height = (image.height * _width) / image.width;
    } else {
    ImgD.width = image.width;
    ImgD.height = image.height;
    }

    }
    }
    }
    },
    error: function () {
    alert("error");
    }
    });
    }
    function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
    }
    window.onload = myfun;
    </script>
    <style type="text/css">
    img {
    max- 100%;
    -ms-interpolation-mode: bicubic;
    vertical-align: bottom;
    }
    </style>

    </head>
    <body id="body">

    <section class="details_bottom"></section>

    <script src="~/Scripts/scrollLazy.js"></script>
    </body>
    </html>

  • 相关阅读:
    构造函数产生的点及原因
    关于未捕获异常的处理(WPF)
    消息协定
    为outlook增加“邮件召回”功能
    MHA故障切换和在线手工切换原理
    Delphi 类型转换函数(有几个函数没见过,FloatToStrF,FloatToText等等)
    Delphi 常用属性说明(超长)
    Delphi程序自删除的几种方法
    CreateFile,ReadFile等API详解(或者说MSDN的翻译)
    去除文件属性(使用SetFileAttributes API函数)
  • 原文地址:https://www.cnblogs.com/niejun/p/4668921.html
Copyright © 2020-2023  润新知