基于vue.js实现图片轮播效果
程序员文章站
2022-05-30 08:07:43
轮播图效果:
1.html
轮播图效果:
1.html
<template> <div class="shuffling"> <div class="fouce fl"> <div class="focus"> <ul class="showimg"> <template v-for='sd in shufflingdata'> <li v-if='shufflingid==$index' v-on:mouseover='showprenext' v-on:mouseout='hiddenprenext'> <a target="_blank" title="{{sd.title}}" class="img" href="{{sd.href}}"><img alt="{{sd.title}}" v-bind:src="sd.url"/></a> <h3><a target="_blank" title="{{sd.title}}" href="{{sd.href}}">{{sd.title}}</a></h3> </li> </template> </ul> <div class='bullet-pagination'> <a class="bullet" v-bind:class="{'active': shufflingid==0}" v-on:click='bulletfunone'></a> <a class="bullet" v-bind:class="{'active': shufflingid==1}" v-on:click='bulletfuntwo'></a> <a class="bullet" v-bind:class="{'active': shufflingid==2}" v-on:click='bulletfunthree'></a> </div> <div v-show='prenext' class="prenext pre" v-on:mouseover='showprenext' v-on:mouseout='hiddenprenext' v-on:click='prefun'></div> <div v-show='prenext' class="prenext next" v-on:mouseover='showprenext' v-on:mouseout='hiddenprenext' v-on:click='nextfun'></div> </div> </div> </div> </template>
2.js
<script> export default { components: { }, ready: function() { var _this=this; var timer = setinterval(function() { if(_this.shufflingid>=0&&_this.shufflingid<_this.shufflingdata.length-1){ _this.shufflingid=parseint(_this.shufflingid)+1; } else if (_this.shufflingid==_this.shufflingdata.length-1) { _this.shufflingid=0; } }, 5000) }, methods: { bulletfunone:function(){ this.shufflingid=0; }, bulletfuntwo:function(){ this.shufflingid=1; }, bulletfunthree:function(){ this.shufflingid=2; }, showprenext:function(){ this.prenext=true; }, hiddenprenext:function(){ this.prenext=false; }, prefun:function(){ var _this=this; if(_this.shufflingid>0&&_this.shufflingid<_this.shufflingdata.length){ _this.shufflingid=parseint(_this.shufflingid)-1; } }, nextfun:function(){ var _this=this; if(_this.shufflingid>=0&&_this.shufflingid<_this.shufflingdata.length-1){ _this.shufflingid=parseint(_this.shufflingid)+1; } } }, data() { return { shufflingdata:[{ title:'喵来个米', href:'1', url:'/xxx/xx/src/img/1.png' }, { title:'豆豆', href:'2', url:'/xxx/xx/src/img/2.png' },{ title:'猫咪咪', href:'3', url:'/xxx/xx/src/img/3.jpg' }], shufflingid:0, prenext:false, } } } </script>
3.css
.fouce { position: relative; left:380px; overflow: hidden; height: 570px; width: 1100px; } .fl { float: left; } .focus{ overflow: hidden; } .fouce ul { position: absolute; } .fouce ul li { float: left; } .fouce ul li a.img { display: block; height: 520px; } .showimg{ width:1440px; left:-0px; } .showimg img { display: block; width:1100px; height:520px; } .fouce .bullet-pagination { position: absolute; bottom: 50px; } .fouce ul li h3 { height: 40px; line-height: 40px; background-color: #ededed; text-align: center; font-size: 25px; width: 1100px; } .bullet-pagination { width: 100%; text-align: center; padding-top: 16px; clear: both; overflow: hidden; } .bullet { display: inline-block; background: #fff; width: 12px; height: 12px; border-radius: 6px; -webkit-border-radius: 6px; margin-right: 5px; opacity: 0.8; -webkit-transition: opacity 0.8s linear; -moz-transition: opacity 0.8s linear; -ms-transition: opacity 0.8s linear; -o-transition: opacity 0.8s linear; transition: opacity 0.8s linear; } .bullet.active { background: #007cdb; opacity: 1; cursor: pointer; } .prenext { display: block; width: 31px; height: 41px; position: absolute; top: 200px; cursor: pointer; } .pre { background: url('/xxx/xx/src/img/news_arr_r.png') no-repeat right center; } .next { background: url('/xxx/xx/src/img/news_arr_r.png') no-repeat left center; right: 0px; } * { padding: 0; margin: 0; list-style: none; } a{ text-decoration: none; }
本文已被整理到了《vue.js前端组件学习教程》,欢迎大家学习阅读。
关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。
精彩专题分享:jquery图片轮播 javascript图片轮播 bootstrap图片轮播
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: 童年的天真和淘气很搞笑
下一篇: 动物爆笑冷幽默