我有来自
background-url
的背景图像,当我输入:background-attachment: fixed;
时,我的视差适用于该图像
怎样才能让背景图片在滚动时移动一点?
这是我正在谈论的示例:
这就是我滚动时所拥有的:http://www.w3schools.com/howto/tryhow_css_parallax_demo.htm
这就是我滚动时想要的: http://materializecss.com/parallax-demo.html
您可以使用 CSS3 的
transform
和 transition
属性的组合来使背景图像具有动画效果。这是如何执行此操作的链接。您可以使用 Javascript 的 onscroll
事件来触发我在悬停时触发的内容。
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
border: 1px solid black;
transition: all 2s;
}
div:hover {
-ms-transform: translate(0px, 100px);
/* IE 9 */
-webkit-transform: translate(0px, 100px);
/* Safari */
transform: translate(0px, 100px);
/* Standard syntax */
}
</style>
</head>
<body>
<div>
Set this css on background image of your element. Use javascript to transform on scroll.
</div>
</body>
</html>