<img>标签视差图像不是背景图像:附加在CSS中

明亮的星星

我试图对标签进行视差效果。但它不起作用。http://prntscr.com/rbq4ha我需要使图像像链接图像一样为视差。请帮我。

TOH19

使用容器元素并将背景图像添加到具有特定高度的容器中。然后使用background-attachment: fixed来创建实际的视差效果。其他背景属性用于完美居中和缩放图像/这里是一个示例:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.parallax {
  /* The image used */
  background-image: url("https://miro.medium.com/max/2046/1*ZJuc_2TsDElu6Gtg_KxiEg.png");

  /* Set a specific height */
  min-height: 500px; 

  /* Create the parallax scrolling effect */
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
</style>
</head>
<body>

<p>Scroll Up and Down this page to see the parallax scrolling effect.</p>

<div class="parallax"></div>

<div style="height:1000px;background-color:red;font-size:36px">
Scroll Up and Down this page to see the parallax scrolling effect.
This div is just here to enable scrolling.
Tip: Try to remove the background-attachment property to remove the scrolling effect.
</div>

</body>
</html>

这是一个简单的教程,介绍如何创建视差滚动。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章