css设置背景图片随滚动缓慢滚动_CSS3 无限滚动的背景图

本文展示了如何使用CSS3动画实现背景图片随着页面滚动而平滑滚动的效果。通过定义关键帧动画和应用`transform: translateY()`,创建了两种不同的滚动样式:一种应用于整个页面背景,另一种应用于特定元素。这种方法可以为网站增添动态视觉效果。
摘要由CSDN通过智能技术生成

CSS

语言:

CSSSCSS

确定

*,

*:before,

*:after {

box-sizing: border-box;

}

@-webkit-keyframes scrollBad {

0% {

background-position: 0 0;

}

100% {

background-position: 0 -320px;

}

}

@-moz-keyframes scrollBad {

0% {

background-position: 0 0;

}

100% {

background-position: 0 -320px;

}

}

@keyframes scrollBad {

0% {

background-position: 0 0;

}

100% {

background-position: 0 -320px;

}

}

@-webkit-keyframes scrollGood {

0% {

transform: translateY(0);

}

100% {

transform: translateY(-320px);

}

}

@-moz-keyframes scrollGood {

0% {

transform: translateY(0);

}

100% {

transform: translateY(-320px);

}

}

@keyframes scrollGood {

0% {

transform: translateY(0);

}

100% {

transform: translateY(-320px);

}

}

.pen {

background-color: blue;

position: absolute;

top: 0px;

left: 0px;

height: 100%;

width: 100%;

}

.panel {

padding: 3rem;

height: 50%;

}

.top {

background-color: #3e69c3;

background-image: url(http://scarbroughstudios.com/img/codepen.svg);

background-position: center center;

background-size: 500px;

-webkit-animation: scrollBad 5s linear infinite;

-moz-animation: scrollBad 5s linear infinite;

animation: scrollBad 5s linear infinite;

}

.bottom {

background-color: #31cc70;

overflow: hidden;

position: relative;

}

.bottom .scroll {

background-image: url(http://scarbroughstudios.com/img/codepen.svg);

background-position: center center;

background-size: 500px;

position: absolute;

top: 0px;

left: 0px;

height: 400%;

width: 100%;

z-index: 1;

-webkit-animation: scrollGood 5s linear infinite;

-moz-animation: scrollGood 5s linear infinite;

animation: scrollGood 5s linear infinite;

}

h1 {

color: white;

font-weight: 400;

font-family: sans-serif;

margin: 0;

position: relative;

z-index: 2;

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值