[英]Changing image size Javascript depending on screensize
Am using bootstrap, which for some reason means whenever i try the @media (min-height: 1000px)
there is no response from the image class. 我正在使用引导程序,由于某种原因,这意味着每当我尝试
@media (min-height: 1000px)
,图像类都没有响应。
I would like to run a javascript that resizes the image when the screen height gets above a certain size. 我想运行一个JavaScript,当屏幕高度超过特定大小时,该图像将调整图像大小。 (Lets say 1000 px)
(假设1000像素)
the best code I have found is this 我发现的最好的代码是这个
<script>
$(function() {
if ($(window).height() >= 710) {
$("img").each(function() {
$(this).attr("src", $(this).attr("src").replace("logo1.png", "logo2.png"));
});
}
});
</script>
However when i replace src with width, and change the corresponding values of logo1.png and logo2.png to 500 and 800 nothing happens. 但是,当我用宽度替换src并将logo1.png和logo2.png的相应值更改为500和800时,什么也没发生。
Any pointers using Javascript very much appreciated. 非常感谢使用Javascript的指针。
I tried this in CSS 我在CSS中尝试过
@media screen and (max-width: 980px) and (min-height: 1000px) {
.iphonegangster {
min-width: 950px;
height: auto;
}
Instead of using JS, you can use CSS media queries with image background. 可以使用具有图像背景的CSS媒体查询来代替JS。 Ex.,
<i role=image class=img1/>
. 例如,
<i role=image class=img1/>
。 Using CSS media query pick image based on screen size. 使用CSS媒体查询根据屏幕大小选择图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.