Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在div中调整大小时触发新图像的问题_Jquery_Css - Fatal编程技术网

Jquery 在div中调整大小时触发新图像的问题

Jquery 在div中调整大小时触发新图像的问题,jquery,css,Jquery,Css,我试图创建一个横幅,当浏览器被重新调整大小时,它会触发加载一个新的图像,这是一个响应网站。我想要一个img以>800px的速度加载,另一个以的速度加载,如下所示: contentCSS属性与::before和::after伪元素一起使用,以生成元素中的内容 您可以执行以下操作,这些操作应适用于所有主要浏览器: HTML: <div class="center-block"></div> @media all and (max-width: 768px) { .cen

我试图创建一个横幅,当浏览器被重新调整大小时,它会触发加载一个新的图像,这是一个响应网站。我想要一个img以>800px的速度加载,另一个以的速度加载,如下所示:

content
CSS属性与
::before
::after
伪元素一起使用,以生成元素中的内容

您可以执行以下操作,这些操作应适用于所有主要浏览器:

HTML:

<div class="center-block"></div>
@media all and (max-width: 768px) {
  .center-block::before {
    content: url("gosalemobile.jpg");
  }
}

@media all and (min-width: 800px) {
  .center-block::before {
    content: url("gosale.jpg");
  }
}
<div class="center-block"></div>
@media all and (max-width: 768px) {
  .center-block {
    background-image: url("gosalemobile.jpg");
    background-repeat: no-repeat;
    background-position: top left;
    background-size: contain;
  }
}

@media all and (min-width: 800px) {
  .center-block {
    background-image: url("gosale.jpg");
    background-repeat: no-repeat;
    background-position: top left;
    background-size: contain;
  }
}

.center-block {
  height: 700px; /* or some other height */
  width: 100%; /* or some other width */
}

或者,您可以使用背景图像和
背景大小:contain

HTML:

<div class="center-block"></div>
@media all and (max-width: 768px) {
  .center-block::before {
    content: url("gosalemobile.jpg");
  }
}

@media all and (min-width: 800px) {
  .center-block::before {
    content: url("gosale.jpg");
  }
}
<div class="center-block"></div>
@media all and (max-width: 768px) {
  .center-block {
    background-image: url("gosalemobile.jpg");
    background-repeat: no-repeat;
    background-position: top left;
    background-size: contain;
  }
}

@media all and (min-width: 800px) {
  .center-block {
    background-image: url("gosale.jpg");
    background-repeat: no-repeat;
    background-position: top left;
    background-size: contain;
  }
}

.center-block {
  height: 700px; /* or some other height */
  width: 100%; /* or some other width */
}
(至少必须指定高度才能使其工作,但我发现这更具响应性)

这两种解决方案都在Edge、Chrome和Firefox上进行了测试。。只是因为JSFIDLE在IE中出错而错过了IE11。

根据:

content
CSS属性与
::before
::after
伪元素一起使用,以生成元素中的内容

您可以执行以下操作,这些操作应适用于所有主要浏览器:

HTML:

<div class="center-block"></div>
@media all and (max-width: 768px) {
  .center-block::before {
    content: url("gosalemobile.jpg");
  }
}

@media all and (min-width: 800px) {
  .center-block::before {
    content: url("gosale.jpg");
  }
}
<div class="center-block"></div>
@media all and (max-width: 768px) {
  .center-block {
    background-image: url("gosalemobile.jpg");
    background-repeat: no-repeat;
    background-position: top left;
    background-size: contain;
  }
}

@media all and (min-width: 800px) {
  .center-block {
    background-image: url("gosale.jpg");
    background-repeat: no-repeat;
    background-position: top left;
    background-size: contain;
  }
}

.center-block {
  height: 700px; /* or some other height */
  width: 100%; /* or some other width */
}

或者,您可以使用背景图像和
背景大小:contain

HTML:

<div class="center-block"></div>
@media all and (max-width: 768px) {
  .center-block::before {
    content: url("gosalemobile.jpg");
  }
}

@media all and (min-width: 800px) {
  .center-block::before {
    content: url("gosale.jpg");
  }
}
<div class="center-block"></div>
@media all and (max-width: 768px) {
  .center-block {
    background-image: url("gosalemobile.jpg");
    background-repeat: no-repeat;
    background-position: top left;
    background-size: contain;
  }
}

@media all and (min-width: 800px) {
  .center-block {
    background-image: url("gosale.jpg");
    background-repeat: no-repeat;
    background-position: top left;
    background-size: contain;
  }
}

.center-block {
  height: 700px; /* or some other height */
  width: 100%; /* or some other width */
}
(至少必须指定高度才能使其工作,但我发现这更具响应性)


这两种解决方案都在Edge、Chrome和Firefox上进行了测试。。只是错过了IE11,因为JSFIDLE在IE中搞砸了。

这是IE11,还有Edge。为什么不使用两个不同的图像呢。一个用于桌面,一个用于移动?。也可以使用“背景图像”属性显示图像。并使用媒体查询来更改背景图像。此外,只有少量浏览器支持content属性。据我所知,它只在webkit/chrome中受支持。它是IE 11,还有Edge。为什么不使用两个不同的图像呢。一个用于桌面,一个用于移动?。也可以使用“背景图像”属性显示图像。并使用媒体查询来更改背景图像。此外,只有少量浏览器支持content属性。据我所知,它仅在webkit/chrome中受支持。因此,这非常有效,我非常感谢,但bootstrap现在似乎在图像底部添加了某种底部填充,这似乎与::以前IE的空间约为20px,google的空间约为4px有关。你知道如何解决这个问题吗?你有没有尝试将
的margin(或padding)属性强制为0。center block
?现在我觉得很愚蠢。这很有魅力。你就是那个人!所以,这很好用,我真的很欣赏,但现在bootstrap似乎在图片底部添加了某种底部填充,这似乎与::之前IE的空间约为20px,而google的空间约为4px。你知道如何解决这个问题吗?你有没有尝试强制使用边距(或填充)属性设置为0,用于
。中间块
?现在我觉得自己很愚蠢。这很有魅力。你就是那个人!