首页 文章

img调整大小,但宽度将停在600

提问于
浏览
0

HTML

<div>
    <div style="overflow: auto">
        <img class="preview_img" src="/myImg" />
        <img class="preview_img" src="/myImg2" />
    </div>
</div>

JS

btnZoomIn.click(function () {
    previewImg.each(function () {
        var width = $(this).width();
        var height = $(this).height();

        var newWidth = width * 1.2;
        var newHeight = height * 1.2;

        $(this).css('width', newWidth);
        $(this).css('height', newHeight);
        // $(this).width(newWidth);
        // $(this).height(newHeight);
    });
});

我想在按钮点击时调整img的大小,宽度将在600px上停止,

但高度可以无限制 .

我没有设置任何max-width属性(属性)

1 回答

  • 0

    也许从其他元素继承 max-width ,所以添加内联样式以防止 max-width 规则:

    previewImg.each(function () {
        $(this).css('max-width','none');
    });
    
    btnZoomIn.click(function () {
    
        previewImg.each(function () {
            var width = $(this).width();
            var height = $(this).height();
    
            var newWidth = width * 1.2;
            var newHeight = height * 1.2;
    
            $(this).css('width', newWidth);
            $(this).css('height', newHeight);
            // $(this).width(newWidth);
            // $(this).height(newHeight);
        });
    });
    

    然后,如果存在问题,请检查父母的 max-widthwidth .

相关问题