VUE开发一个图片轮播的组件
完成效果图如下:

vue开发的思路主要是数据绑定,代码如下:
<template>
<div ref="root" style="user-select: none;-webkit-user-select: none;overflow: hidden">
<div class="sliderPanel"
:class="{transitionAni:ani}"
:style="{height:height,transform:translateX}">
<div v-for="item in itemList" class="verticalCenter picbox" :style="{left:item.x+'px'}">
<img :style="{width:width,top:top}" :src="item.url" style="min-height: 100%">
</div>
</div>
<div @click="clickLeft" class="arrowLeft verticalCenter horizaCenter">
<img src="./image/arrow.png" style="transform: rotate(180deg)">
</div>
<div @click="clickRight" class="arrowRight verticalCenter horizaCenter">
<img src="./image/arrow.png">
</div>
<div class="arrowBottom verticalCenter horizaCenter" >
<img src="./image/arrow.png" style="transform: rotate(90deg) scale(0.7)">
</div>
<div class="sliderBar horizaCenter">
<div v-for="(item,index) in imgArray" @click="clickSliderCircle(index)" class="circle" :class="{circleSelected:item.selected}">
</div>
</div>
</div>
</template>
<script>
const SCREEN_WIDTH=document.body.clientWidth
const SCREEN_HEIGHT=document.body.scrollHeight
var left,center,right
var selectIndex=0
var count=0
var second=3//slider 时间间隔
var timer=null
var ani=null
var debugScale=1.0//测试用可调整为小于1
var Direction={left:'left',right:'right'};
var autoDirection=Direction.right
var canClick=true
export default({
data:function(){
return{
width:'100%',
height:SCREEN_HEIGHT+'px',
top:0,
ani:true,
translateX:'scale('+debugScale+') translateX(0px)',
imgArray:[
{
x:0,
title1:'现在,在您的实验室',
tilte2:'也可以轻松完成无创DNA产前检测',
title3:'了解详细流程',
click_url:'http://www.berrygenomics.com/products/nextseq-cn500/cn500test/',
url:'static/image/1.jpg',
selected:false,
},
{
x:0,
title1:'Sequel开启新基因组时代',
tilte2:'覆盖十余种胎儿染色体疾病,体验升级,呵护加倍',
title3:'了解更多',
click_url:'http://www.berrygenomics.com/products/nextseq-cn500/cn500test/',
url:'static/image/2.jpg',
},
{
x:0,
title1:'BRCA1/2全外显子基因突变检测',
tilte2:'也可以轻松完成无创DNA产前检测',
title3:'了解详细流程',
click_url:'http://www.berrygenomics.com/products/nextseq-cn500/cn500test/',
url:'static/image/3.jpg',
},
{
x:0,
title1:'现在,在您的实验室',
tilte2:'也可以轻松完成无创DNA产前检测',
title3:'了解详细流程',
click_url:'http://www.berrygenomics.com/products/nextseq-cn500/cn500test/',
url:'static/image/4.jpg', },
{
x:0,
title1:'现在,在您的实验室',
tilte2:'也可以轻松完成无创DNA产前检测',
title3:'了解详细流程',
click_url:'http://www.berrygenomics.com/products/nextseq-cn500/cn500test/',
url:'static/image/5.jpg',
},
{
x:0,
title1:'现在,在您的实验室',
tilte2:'也可以轻松完成无创DNA产前检测',
title3:'了解详细流程',
click_url:'http://www.berrygenomics.com/products/nextseq-cn500/cn500test/',
url:'static/image/6.jpg',
},
{
x:0,
title1:'现在,在您的实验室',
tilte2:'也可以轻松完成无创DNA产前检测',
title3:'了解详细流程',
click_url:'http://www.berrygenomics.com/products/nextseq-cn500/cn500test/',
url:'static/image/7.jpg',
},
{
x:0,
title1:'现在,在您的实验室',
tilte2:'也可以轻松完成无创DNA产前检测',
title3:'了解详细流程',
click_url:'http://www.berrygenomics.com/products/nextseq-cn500/cn500test/',
url:'static/image/8.jpg',
}
],
itemList:[]
}
},
mounted:function(){
ani=this.$refs.root.querySelector('.sliderPanel')
count=this.imgArray.length
this.setIndex(selectIndex)
//自动滚动切换图片
this.slideAuto(second)
},
methods:{
clickLeft:function(){
if(!canClick) return false
autoDirection=Direction.left
this.slideAuto(second)
this.moveLeftAni()
canClick=false
},
clickRight:function(){
if(!canClick) return false
autoDirection=Direction.right
this.slideAuto(second)
this.moveRightAni()
canClick=false
},
slideRight:function () {
selectIndex++
if(selectIndex+1>count){
selectIndex=0
}else if(selectIndex<0){
selectIndex=count-1
}
this.setIndex(selectIndex)
},
slideLeft:function () {
selectIndex--
if(selectIndex+1>count){
selectIndex=0
}else if(selectIndex<0){
selectIndex=count-1
}
this.setIndex(selectIndex)
},
clickSliderCircle:function (index) {
this.slideAuto(second)
this.setIndexPre(index)
},
setIndexPre:function (index) {
if(!canClick) return false
canClick=false
if(index==selectIndex)return
var leftIndex=index
var centerIndex=selectIndex
var rightIndex=index
for(var i=0;i<count;i++){
if(i==selectIndex){
this.imgArray[i].selected=true
}else{
this.imgArray[i].selected=false
}
}
left=this.imgArray[leftIndex]
center=this.imgArray[centerIndex]
right=this.imgArray[rightIndex]
left=JSON.parse(JSON.stringify(left))
right=JSON.parse(JSON.stringify(right))
left.x=-SCREEN_WIDTH
center.x=0
right.x=SCREEN_WIDTH
left.index=leftIndex
center.index=centerIndex
right.index=rightIndex
this.itemList=[left,center,right]
if(index>selectIndex){
autoDirection=Direction.right;
+function(obj){
obj.anicompted(
'scale('+debugScale+') translateX('+0+'px)',
'scale('+debugScale+') translateX('+-SCREEN_WIDTH+'px)',
function(){
obj.setIndex(index)
})
}(this)
//右移
}else if(index<selectIndex){
//左移
autoDirection=Direction.left;
+function(obj){
obj.anicompted(
'scale('+debugScale+') translateX('+0+'px)',
'scale('+debugScale+') translateX('+SCREEN_WIDTH+'px)',
function(){
obj.setIndex(index)
})
}(this)
}
},
setIndex:function (index) {
var leftIndex=index-1
var centerIndex=index
var rightIndex=index+1
if(index<=0){
index=0
leftIndex=count-1
centerIndex=index
rightIndex=index+1
}else if(index>=count-1){
index=count-1
leftIndex=index-1
centerIndex=index
rightIndex=0
}
selectIndex=index
for(var i=0;i<count;i++){
if(i==selectIndex){
this.imgArray[i].selected=true
}else{
this.imgArray[i].selected=false
}
}
left=this.imgArray[leftIndex]
center=this.imgArray[centerIndex]
right=this.imgArray[rightIndex]
left.x=-SCREEN_WIDTH
center.x=0
right.x=SCREEN_WIDTH
left.index=leftIndex
center.index=centerIndex
right.index=rightIndex
this.itemList=[left,center,right]
},
slideAuto:function () {
clearInterval(timer);
+function (obj) {
timer=setInterval(function () {
if(autoDirection==Direction.left){
obj.moveLeftAni()
}else{
obj.moveRightAni()
}
},second*1000)
}(this)
},
moveLeftAni:function(){
+function(obj){
obj.anicompted(
'scale('+debugScale+') translateX('+0+'px)',
'scale('+debugScale+') translateX('+SCREEN_WIDTH+'px)',
function(){
obj.slideLeft()
})
}(this)
},
moveRightAni:function(){
+function(obj){
obj.anicompted(
'scale('+debugScale+') translateX('+0+'px)',
'scale('+debugScale+') translateX('+-SCREEN_WIDTH+'px)',
function(){
obj.slideRight()
})
}(this)
},
anicompted:function(fromStr,toStr,callBack){
var handler=null,obj=this
handler=function(){
ani.removeEventListener('webkitTransitionEnd',handler,false)
callBack()
obj.ani=false
obj.translateX=fromStr
canClick=true
}
ani.removeEventListener('webkitTransitionEnd',handler,false)
ani.addEventListener('webkitTransitionEnd',handler,false)
this.ani=true
this.translateX=toStr
}
} }) </script>
<style scoped>
.transitionAni{
transition: all 0.8s cubic-bezier(.23,1,.32,1);
/*transition: transform 1s;*/
}
.arrowLeft{
transition: all 0.4s ease;
width: 60px;
height: 60px;
position: absolute;
left: 15px;
top: 50%;
margin-top: -30px;
background: rgba(0,0,0,0.6);
border-radius: 6px;
}
.arrowLeft:hover{
background: rgba(0,0,0,0.8);
transform: scale(1.1);
}
.arrowRight{
transition: all 0.4s ease;
width: 60px;
height: 60px;
position: absolute;
right: 15px;
top: 50%;
margin-top: -30px;
background: rgba(0,0,0,0.6);
border-radius: 6px;
}
.arrowRight:hover{
background: rgba(0,0,0,0.8);
transform: scale(1.1);
}
.sliderBar{
width:100%;height: auto;position: absolute;bottom: 50px;
}
.circle{
width: 15px;
height: 15px;
background: rgba(0,0,0,0.7);
border-radius: 50%;
display: table-cell;
margin-right: 3px;
transition: all 0.5s ease;
}
.circle:hover{
background: #C7015C;
transform: scale(1.15);
}
.circleSelected{
background: #C7015C;
transform: scale(1.15);
}
.arrowBottom{
width: 80px;
height: 50px;
position: absolute;
bottom: -15px;
left: 50%;
margin-left: -40px;
background: #C7015C;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
transition: all 0.5s ease-out;
}
.arrowBottom:hover{
transform: translateY(-10px);
background: deeppink;
}
.picbox{
width: 100%;
height: 100%;
position: absolute;
top: 0;
overflow: hidden;
/*transform: scale(0.9);*/
/*opacity: 0.2;*/
transition: all 0.45s ease;
}
/*@keyframes arrowOut-animation {*/
/*from{*/
/*transform: translateY(0px);*/
/*}*/
/*to{*/
/*transform: translateY(15px);*/
/*!*width:200px;*!*/
/*}*/
/*}*/
/*@keyframes arrowIn-animation {*/
/*from{*/
/*transform: translateY(15px);*/
/*}*/
/*to{*/
/*transform: translateY(0px);*/
/*!*height: 200px;*!*/
/*}*/
/*}*/
/*.arrowOut{*/
/*animation: arrowOut-animation;*/
/*animation-duration: 0.5s;*/
/*animation-timing-function: ease-out;*/
/*animation-fill-mode:forwards;*/
/*}*/
/*.arrowIn{*/
/*animation: arrowIn-animation;*/
/*animation-duration: 0.5s;*/
/*animation-timing-function:ease-out;*/
/*animation-fill-mode:forwards;*/ /*}*/
</style>
VUE开发一个图片轮播的组件的更多相关文章
- Vue学习—Vue写一个图片轮播组件
1.先看效果: 熟悉的图片轮播,只要是个网站,百分之90以上会有个图片轮播.我认为使用图片轮播. 第一可以给人以一种美观的感受,而不会显得网站那么呆板, 第二可以增加显示内容,同样的区域可以显示更多内 ...
- Angular2组件与指令的小实践——实现一个图片轮播组件
如果说模块系统是Angular2的灵魂,那其组件体系就是其躯体,在模块的支持下渲染出所有用户直接看得见的东西,一个项目最表层的东西就是组件呈现的视图.而除了直接看的见的躯体之外,一个完整的" ...
- 基于ionic框架封装一个图片轮播指令的几点
在这里我想在项目中封装一个图片轮播的指令 (本项目使用的是ionic框架) 1)定义指令 define(['app'],function(myapp){ myapp.directive('myslid ...
- 实现一个图片轮播-3d播放效果
前言:最近在做一个音乐播放器,首页要做一个图片轮播,看了bootstrap的carousel插件以及移动端的swipe.js库,都是平面图片轮播的效果,所以自己想着实现类似网易云app里那种3d图片轮 ...
- 继上一篇随笔,优化3张以上图片轮播React组件
import React from 'react'; import PropTypes from 'prop-types'; import {getSwipeWay} from '../utils/s ...
- vue实例之组件开发:图片轮播组件
一.普通方式: 其中,index是关键. <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- Unslider Web前端框架之图片轮播
前端框架,前端组件,前端库,都是一个意思,能看源码. 最近做H5小游戏,用到了图片轮播的组件,而且要求支持移动端触屏滑动.一开始用的是nivo slider,但是对大小不一样的图不支持box 的参数设 ...
- 基于面向对象的图片轮播(js原生代码)
无论你想走多远,你都需要不断地走下去.前端最精华的便是原生的js,这也是我们前端工程师的技术分层的重要指标,也提现这你的代码能力,开发的水平.废话不多说,进入今天的主要分享————基于面向对象思想的图 ...
- html css+div+jquery实现图片轮播
一直想自己动手做一个图片轮播的控件,查查网上的资料大多引用已经做好的组件,其原理算法不是很清楚,于是自己用jquery写了一个.先看下效果图: 主要界面实现思路如下: 1.新建一个div宽度为100% ...
随机推荐
- 通俗理解BFS和DFS,附基本模板
1.BFS(宽度优先搜索):使用队列来保存未被检测的节点,按照宽度优先的顺序被访问和进出队列 打个比方:(1)类似于树的按层次遍历 (2)你的眼镜掉在了地上,你趴在地上,你总是先摸离你最近的地方,如果 ...
- 【厚积薄发】Crunch压缩图片的AssetBundle打包
这是第133篇UWA技术知识分享的推送.今天我们继续为大家精选了若干和开发.优化相关的问题,建议阅读时间10分钟,认真读完必有收获. UWA 问答社区:answer.uwa4d.com UWA QQ群 ...
- js数组的比较
如果两个数组元素个数都相等,但排序不同,那么它两个相等吗?结果肯定是否定的.但如果先调用sort()方法进行排序,结果就是true了. console.log(a.sort().toString()= ...
- python破解网吧收费系统,远控网吧电脑设备!
我今天呢 , 我就没事跟着朋友喝酒喝酒啊.喝了很多啊.晚上到旁边的酒店开了一个房间,到了酒店才十点! 感觉没啥事情干的,那就去网吧走走看把,看到是一个嘟嘟牛的,和上次是一样的.还是照常用MS170 ...
- Netty源码分析第7章(编码器和写数据)---->第5节: Future和Promies
Netty源码分析第七章: 编码器和写数据 第五节: Future和Promise Netty中的Future, 其实类似于jdk的Future, 用于异步获取执行结果 Promise则相当于一个被观 ...
- php学习--变量和数据类型
PHP变量 变量 程序执行期间,可以变化的量即为变量. 声明变量 以美元$ 符号声明 注意:(PHP严格区分大小写) 变量名称以 字母.或下划线开始,后面跟上数字/字母/下划线,不能包含特殊字符 ...
- 吴恩达(Andrew Ng)——机器学习笔记1
之前经学长推荐,开始在B站上看Andrew Ng的机器学习课程.其实已经看了1/3了吧,今天把学习笔记补上吧. 吴恩达老师的Machine learning课程共有113节(B站上的版本https:/ ...
- 服务端模版注入漏洞检测payload整理
服务端模版注入漏洞产生的根源是将用户输入的数据被模版引擎解析渲染可能导致代码执行漏洞 下表涵盖了java,php,python,javascript语言中可能使用到的模版引擎,如果网站存在服务端模版注 ...
- roadhog中如何拷贝文件
一:使用 public 目录 我们约定 public 目录下的文件会在 server 和 build 时被自动 copy 到输出目录(默认是 ./dist)下.所以可以在这里存放 favicon, i ...
- 第二阶段每日站立会议Third Day
昨天对图片显示的大小进行调整 今天对于程序中的字体显示进行细化修改,使界面更美观 遇到的问题:当图片太小时,显示一块灰色区域,不美观