vue使用设置背景图片的方式实现淡入淡出轮播图

背景图片淡入淡出效果

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="telephone=no,email=no" name="format-detection">
<meta content="yes" name="apple-touch-fullscreen">
<title>进度条</title>
<style>
*{margin:0;padding:0;}
#ulmian{
position:relative;
width:100%;
overflow:hidden;
}
#ulmian li{
position:absolute;
height:100%;
opacity:0;
transition:opacity 1s;
}
#ulmian li:first-child{
position:absolute;
height:100%;
opacity:1;
}
#ulmian li img{
width:100%;
height:100%;
background-size: 100% 100%;
  position: fixed;
}
#last{
position:absolute;
width:60px;
height:30px;
text-align:center;
font-size:14px;
background:rgba(0,0,0,0.8);
line-height:30px;
top:50%;
margin-top:15px;
left:0;
color:#fff;
cursor:pointer;
}
#next{
position:absolute;
width:60px;
height:30px;
text-align:center;
font-size:14px;
background:rgba(0,0,0,0.8);
line-height:30px;
top:50%;
margin-top:15px;
right:0;
color:#fff;
cursor:pointer;
}
*::selection{
background:none;
}
</style>
</head>
<body>
<div style="position:relative;">
<ul id="ulmian">
<li><img src="denglu1.jpg"></li>
<li><img src="denglu2.jpg"></li>
<li><img src="denglu3.jpg"></li>
</ul>
<div id="last">last</div>
<div id="next">next</div>
</div>  

<script>
// window.onload = function(){
// document.getElementById("ulmian").style.height = window.screen.height + 'px';
// }
// window.onresize = function(){
// document.getElementById("ulmian").style.height = window.screen.height + 'px';
// }
//点击next按钮跳转到下一页
var next = document.getElementById("next");
var last = document.getElementById("last");
var oLi = document.getElementById("ulmian").getElementsByTagName("li");
var index = 0;
next.onclick = function(){
index++;
if(index == oLi.length){
index = 0;
}
for(var i=0;i<oLi.length;i++){
oLi[i].style.opacity = "0";
}
oLi[index].style.opacity = "1";  

}
last.onclick = function(){
index--;
if(index == -1){
index = oLi.length-1;
}
for(var i=0;i<oLi.length;i++){
oLi[i].style.opacity = "0";
}
oLi[index].style.opacity = "1";  

}

</script>  
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值