如何使用 jQuery 在移动设备上调整图像大小? [英] How to resize image on mobile devices using jQuery?

查看:47
本文介绍了如何使用 jQuery 在移动设备上调整图像大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个移动网站上工作,我有一个 div &里面的图片是这样的:

<div id="content">我的 img 标签在这里</div>

我想知道,如何在任何手机/平板电脑上调整图像大小,而无需担心其分辨率、大小或方向.在这里,我正在寻找基于上述场景的最佳解决方案.

解决方案

我找到了一个使用 jquery 的简单解决方案....

$(document).ready(function() {$width = $('#content').width();$('#content img').css({'最大宽度':$width,'高度':'自动'});});

I am working on a mobile website and I have a div & image inside it like this:

<div id="wrapper">
    <div id="content">My img tag here</div>
</div>

I want to know, how I can resize the image on any phone/tablet without worrying about its resolution, size or orientation. Here, I am looking for the best possible solution based on the above scenarios.

解决方案

I found a simple solution using jquery....

$(document).ready(function() {

    $width = $('#content').width();

    $('#content img').css({
        'max-width': $width,
        'height': 'auto'
    });
});

这篇关于如何使用 jQuery 在移动设备上调整图像大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆