uniapp设计一个封面,有动态图,写代码
时间: 2024-05-31 18:08:11 浏览: 147
<template>
<view class="container">
<image class="bg-img" src="/static/img/bg.jpg"></image>
<view class="mask"></view>
<view class="content">
<image class="logo" src="/static/img/logo.png"></image>
<view class="title">UniApp动态封面设计</view>
<view class="desc">一起来学习UniApp,打造炫酷动态封面</view>
<image class="arrow" src="/static/img/arrow.png"></image>
</view>
</view>
</template>
<script>
export default {
data() {
return {
bgScrollLeft: 0,
bgTimer: null
}
},
mounted() {
this.startBgAnimation()
},
methods: {
startBgAnimation() {
this.bgTimer = setInterval(() => {
this.bgScrollLeft++
if (this.bgScrollLeft >= 750) {
this.bgScrollLeft = 0
}
this.$refs.bgImg.style.transform = `translateX(-${this.bgScrollLeft}px)`
}, 20)
}
},
beforeDestroy() {
clearInterval(this.bgTimer)
}
}
</script>
<style>
.container {
position: relative;
width: 750rpx;
height: 1334rpx;
overflow: hidden;
}
.bg-img {
position: absolute;
top: 0;
left: 0;
width: 1500rpx;
height: 1334rpx;
}
.mask {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
}
.content {
position: absolute;
top: 280rpx;
left: 0;
width: 100%;
text-align: center;
}
.logo {
width: 200rpx;
height: 200rpx;
margin: 0 auto;
}
.title {
font-size: 60rpx;
font-weight: bold;
color: #fff;
margin-top: 50rpx;
}
.desc {
font-size: 36rpx;
color: #fff;
margin-top: 30rpx;
}
.arrow {
width: 80rpx;
height: 80rpx;
margin-top: 50rpx;
animation: arrow 1s ease-in-out infinite;
}
@keyframes arrow {
0% {
transform: translateY(0);
}
50% {
transform: translateY(40rpx);
}
100% {
transform: translateY(0);
}
}
</style>
阅读全文
相关推荐
















