javascript - 调整窗口大小时如何流动图像?

标签 javascript jquery html css

如何在调整窗口大小时使图像流畅?

我有这样的 HTML 代码:

<div class="box">
 <img src="http://demo.smooththemes.com/magazon/wp-content/uploads/2013/01/984632486_9d8ff89b63_b-642x336.jpg" />
</div>

和 CSS:

.box {width:150px; height:60px; position:relative; overflow:hidden}
.box img{position:absolute; width:180px; height:80px; top:-10px; left:-10px}

调整窗口大小时,我想删除 (.box img) 的属性:top:-10px; left:-10px 和属性 more : min-width:100%, max-width:100%。这意味着我们有:

.box img{
position:absolute;
width:180px; height:80px; min-width:100%;  
top:(removed); left:(removed)}

如何使用 Javascript 或 Jquery 来实现。感谢您的帮助。

最佳答案

我倾向于同意@Phorden 的观点,即媒体查询是一个很好的途径。

但是,如果您需要使用 JS/jQuery 来完成:

$(window).resize(function() {
    $('.box img').css({'top': 'auto', 'left': 'auto', 'min-width': '100%'});
});

关于javascript - 调整窗口大小时如何流动图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19593351/

相关文章:

javascript - 如何在 for 循环中跳过 cy.get() 函数

javascript - 正则表达式表现得很奇怪

css - 为什么 div 会溢出 HTML 中的父包装器

html - 如何使用网格结构嵌入视频?

Javascript 表单提交按钮不起作用 insideHTML

javascript - node.js 将变量公开给模块?

php - 如何处理Jquery.ajax触发的php脚本中的错误?

javascript - 为什么我的 jQuery UI CSS 在 JSFiddle 中不起作用?

jquery - webkit-transform 溢出 :auto div results in vanishing scrollbar in Chrome

javascript - 如何使用图像创建大复选框?