jquerymobile允许图像仅在其实际尺寸内调整大小

时间:2014-11-26 11:11:16

标签: image jquery-mobile image-resizing

我正在使用jquery mobile,我希望停止调整图像大小超过其实际尺寸,但是如果更小,特别是在桌面上显示时仍然允许调整大小

我已经在下面推出了我自己的代码,这可以正常工作(ish),但我目前有2个问题

  1. 当图像调整大小超出其实际大小时,我会在显示图像时屏幕闪烁,但代码会启动并重新显示为较小的尺寸
  2. 双击浏览器标题栏
  3. 时,它并不总是调整大小

    有人可以帮忙/建议吗?

    <img  id="imgs" style="width:90%;" src="images/mypic.jpg" />
    
    $(document).on('pageshow', '#index', function (event) {
        resizeimage(awidth, aheight)
    });
    
    $(window).resize(function () {
        resizeimage(awidth, aheight)
    });
    
    function resizeimage(maxwidth, maxheight) {
    
        var width = $(imgs).width(); // Current image width
        var height = $(imgs).height(); // Current image height
    
        // **** this is trace output only
        //$(windowwidth).text($(window).width());
        //$(windowheight).text($(window).height());
        //$(iwidth).text($(imgs).width());
        //$(iheight).text($(imgs).height());
    
        if (parseInt(width, 10) > maxwidth) {
            //$(info).text('bigger');  // trace output
            $(imgs).css("width", maxwidth); // dont allow image to resize larger than its actual                              size
        } else {
            //$(info).text('smaller');          // trace output
            $(imgs).css("width", "100%"); // allow image to resize below its actual size 
        }
    }
    

0 个答案:

没有答案