【问题标题】:Change item height if it width is more than 500px - jQuery [closed]如果宽度超过 500 像素,则更改项目高度 - jQuery [关闭]
【发布时间】:2018-06-26 22:09:58
【问题描述】:
我在页面上有一个项目(500x200),当它的宽度超过500px时,高度应该增加到400。
用jQuery可以做到吗?
【问题讨论】:
-
-
-
-
使用 JQuery,您可以使用方法.resize() 了解何时发生调整大小,然后更改元素的大小。
-
标签:
javascript
jquery
html
css
【解决方案1】:
你可以使用调整大小
$( '#item' ).resize(function() {
if($( '#item').width()>500)
{
$( '#item').height($( '#item').height()+400);
}
});
【解决方案2】:
是的,您可以使用 jquery 进行如下操作:-
if (window.matchMedia("(min-width: 501px)").matches) {
alert('this is working with only more than 500px width');
}
【解决方案3】:
$('#myimage').width(500); // 单位假定为像素
$('#myimage').height(400);