上下层叠轮播图

1.效果

2.代码

<template>
	<div class="article-main" @mouseover='mouseOver()' @mouseleave="mouseLeave()">
		<img src="../../assets/a3.jpeg" :class="v1" />
		<img src="../../assets/a2.jpeg" :class="v2" />
		<img src="../../assets/a1.jpeg" :class="v3" />
		<div class="dot-view">
			<div :class="dot1">
			</div>
			<div :class="dot2">
			</div>
			<div :class="dot3">
			</div>
		</div>
		<div class="arrow-view" v-show="isActive">
			<img src="../../assets/btn-l-d.png" class="arrow-left" @click="toLeft()" />
			<img src="../../assets/btn-r-d.png" class="arrow-right" @click="toRight()" />
		</div>
	</div>
</template>
<script>
	export default {
		name: 'home',
		data() {
			return {
				timer: '',
				isActive: false,
				value: 1,
				v1: 'banner wz1',
				v2: 'banner wz2',
				v3: 'banner wz3',
				dot1: 'dot-1 dot-color-actived',
				dot2: 'dot-2 dot-color-normal',
				dot3: 'dot-3 dot-color-normal'
			}
		},
		methods: {
			toLeft() {
				this.value--
				if (this.value == 0) {
					this.value = 3
				}
				this.changeClasss()
			},
			toRight() {
				this.value  
				if (this.value > 3) {
					this.value = 1
				}
				this.changeClasss()
			},
			mouseOver() {
				this.isActive = true
				clearInterval(this.timer);
			},
			// 移出
			mouseLeave() {
				this.isActive = false
				this.timer = setInterval(this.get, 3000);
			},
			changeClasss() {
				if (this.value == 1) {
					this.v1 = 'banner wz1'
					this.v2 = 'banner wz2'
					this.v3 = 'banner wz3'
					this.dot1 = 'dot-1 dot-color-actived'
					this.dot2 = 'dot-2 dot-color-normal'
					this.dot3 = 'dot-3 dot-color-normal'
				}
				if (this.value == 2) {
					this.v1 = 'banner wz2'
					this.v2 = 'banner wz3'
					this.v3 = 'banner wz1'
					this.dot1 = 'dot-1 dot-color-normal'
					this.dot2 = 'dot-2 dot-color-actived'
					this.dot3 = 'dot-3 dot-color-normal'
				}
				if (this.value == 3) {
					this.v1 = 'banner wz3'
					this.v2 = 'banner wz2'
					this.v3 = 'banner wz1'
					this.dot1 = 'dot-1 dot-color-normal'
					this.dot2 = 'dot-2 dot-color-normal'
					this.dot3 = 'dot-3 dot-color-actived'
				}
			},
			get() {
				this.value  ;
				if (this.value > 3) {
					this.value = 1
				}
				this.changeClasss()
			}
		},
		mounted() {
			this.timer = setInterval(this.get, 3000);
		},
		beforeDestroy() {
			clearInterval(this.timer);
		},
	}
</script>
<style scoped>
	.arrow-left {
		position: absolute;
		left: 20px;
		top: 250px;
		cursor: pointer;
	}
	.arrow-right {
		position: absolute;
		left: 280px;
		top: 250px;
		cursor: pointer;
	}
	.article-main {
		width: 320px;
		height: 300px;
		background-color: #aaffff;
		position: relative;
	}
	.banner {
		border-radius: 4px;
		position: absolute;
		transition: all 1s;
	}
	.wz1 {
		width: 280px;
		height: 200px;
		left: 20px;
		z-index: 777;
		top: 20px;
	}
	.wz2 {
		width: 290px;
		height: 200px;
		left: 15px;
		top: 30px;
		z-index: 888;
	}
	.wz3 {
		width: 300px;
		height: 200px;
		left: 10px;
		top: 40px;
		z-index: 999;
	}
	.dot-view {
		position: absolute;
		left: 120px;
		top: 255px;
		display: flex;
		flex-direction: row;
	}
	.dot-color-actived {
		background-color: #ff0000;
	}
	.dot-color-normal {
		background-color: #333;
	}
	.dot-1 {
		width: 10px;
		height: 10px;
		border-radius: 50%;
	}
	.dot-2 {
		width: 10px;
		height: 10px;
		border-radius: 50%;
		margin-left: 20px;
	}
	.dot-3 {
		margin-left: 20px;
		width: 10px;
		height: 10px;
		border-radius: 50%;
	}
</style>

原生轮播图(无缝轮播图)

效果图

<template>
  <div>
    <div class="swiper">
      <ul ref="swiper" class="swipero">
        <li v-for="(item, index) in items" :key="index">
          <div v-text="item.name"></div>
        </li>
      </ul>
    </div>
    <div @click="preNext()">下一页</div>
    <div @click="preLast()">上一页</div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      items: [
        { id: 1, name: "1" },
        { id: 1, name: "2" },
        { id: 1, name: "3" },
      ],
      timer: null,
      active: 0,
      flag: true,
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    // 初始化克隆一个元素,用来解决视觉差的效果(瞬移)
    init() {
      let swiper = this.$refs.swiper;
      let first = swiper.firstElementChild.cloneNode(true);
      swiper.appendChild(first);
    },
    //下一页
    next() {
      let swiper = this.$refs.swiper;
      // 判断是否是最后一个
      // debugger;
      if (this.$refs.swiper.children.length - 2 <= this.active) {
        // debugger
        setTimeout(() => {
          let swiper = this.$refs.swiper;
          this.active = 0;
          swiper.style.transition = "none";
          swiper.style.left = -200 * this.active   "px";
        }, 500);
      }
      this.active  ;
      swiper.style.transition = "all .5s";
      swiper.style.left = -200 * this.active   "px";
    },
    // 上一页
    pre() {
      let swiper = this.$refs.swiper;
      // 判断是否是第一个,线瞬间移动到最后,然后再实现动画效果
      if (this.active == 0) {
        let len = this.$refs.swiper.children.length;
        this.active = len - 1;
        // debugger
        swiper.style.transition = "none";
        swiper.style.left = -200 * this.active   "px";
        setTimeout(() => {
          this.active = len - 2;
          swiper.style.transition = "all .5s";
          swiper.style.left = -200 * this.active   "px";
        }, 300);
      } else {
        this.active--;
        swiper.style.transition = "all .5s";
        swiper.style.left = -200 * this.active   "px";
        // this.swiper();
      }
    },
    // 节流
    throttle(callback,speed=3000) {
      let self = this;
      if (self.flag) {
        clearTimeout(this.timer);
        self.timer = setTimeout(() => {
          callback();
          self.flag = true;
        }, speed);
      }
      this.flag = false;
    },
    // 下一页(节流)
    preNext() {
      this.throttle(this.next,1000);
    },
    // 上一页(节流)
    preLast() {
      this.throttle(this.pre,1000);
    },
    // 自动轮播
    swiper() {
      let self = this;
      setInterval(() => {
        self.pre();
      }, 3000);
    },
  },
};
</script>
<style lang="less" scoped>
.swiper {
  width: 200px;
  height: 200px;
  overflow: hidden;
  position: relative;
  ul {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100vw;
    white-space: nowrap;
    li {
      width: 200px;
      height: 200px;
      display: inline-block;
      vertical-align: bottom;
      position: relative;
      // margin-right: 20px;
      transition: all 0.5s;
      > div {
        width: 100%;
        height: 100%;
      }
      &:nth-child(1) {
        background-color: aquamarine;
      }
      &:nth-child(2) {
        background-color: rgb(255, 204, 127);
      }
      &:nth-child(3) {
        background-color: rgb(255, 127, 144);
      }
      &:nth-child(4) {
        background-color: rgb(127, 255, 223);
      }
    }
    .active {
      width: 400px;
      height: 400px;
    }
  }
}
</style>

以上为个人经验,希望能给大家一个参考,也希望大家多多支持Devmax。

Vue实现上下层叠轮播图的更多相关文章

  1. Vue如何指定不编译的文件夹和favicon.ico

    这篇文章主要介绍了Vue如何指定不编译的文件夹和favicon.ico,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  2. bootstrapv4轮播图去除两侧阴影及线框的方法

    这篇文章主要介绍了bootstrapv4轮播图去除两侧阴影及线框的方法,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  3. AmazeUI图片轮播效果的示例代码

    这篇文章主要介绍了AmazeUI图片轮播效果的示例代码,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  4. Swift版本的图片轮播器框架

    大家在使用的时候,只需要像这样:一个图片轮播器就完成了,是不是很简单呢?赶紧试试吧~如果框架中有什么bug,还请大家多多指教哦.图片效果如下:第一个自己写的框架,难免有不完善的地方,希望大家能帮着作者君一起完成哦~~补充:那天,这篇博客被隔壁老王看到了,把我狠狠的吐槽了一下。你这个毫无特色的图片轮播器也好意思上传?敢不敢来个炫一点的,于是,小汤就又含泪添加了一个比较酷炫的图片轮播器效果。。。

  5. 源码推荐(7.21):顶部滑动菜单FDSlideBar,Swift版无限循环轮播图

    顶部滑动菜单FDSlideBarFDSlideBar是一个顶部滑动菜单,如常见的网易、腾讯新闻等样式。菜单间切换流畅,具有较好的体验性。测试环境:Xcode6.2,iOS6.0以上Swift版无限循环轮播图无限循环轮播图片点击代理可设置图片Url的数组Url和本地图片混合轮播测试环境:Xcode6.2,iOS7.0以上弹幕系统实现--QHDanumuDemo说明:QHDanmu文件夹下是主要的弹幕模块系统,QHDanmuSend文件夹下是简单的发射弹幕的界面。

  6. Swift轮播图的实现及原理(支持xib)

    功能:无限循环轮播图片点击代理本地、远端图片混设支持code、xib、storyboard调用支持旋转支持iPhone、iPad运行展示图:使用方法:下载后直接把CircleView.swift和CircleView.xib这2个文件拉进项目中pod添加kingfisherxib||storyboard:code:添加:下步计划:支持pod开放更多功能如有意见,欢迎issue项目地址:swift无限自动循环轮播图

  7. Swift-轻松实现图片轮播

    我写android的时候实现图片轮播用的viewpager,其实还算可以,也不是特麻烦,用swift实现图片轮播我用的scrollview+pageControl,今天我记录一下实现的过程,理清一下思路。这个一个scrollview,横着放,里面放了四张图片,计算出图片的frame,实现轮播的时候,我们去计算scrollview的offset偏移量,然后用定时器timer去触发滚动,计算当前的偏移量和page,配合pageControll,指示器改变,当到达最后一张图片的时候我们把page设为0。错误总结

  8. Swift图片轮播的代码

    //提示当前滚动的图片,指示器;拖动几张图片到Images.xcassets中,本例子拖动5张图片,名字分别为gallery1.....gallery5.4)在类内定义一个NSTimer类型的定时器:vartimer:NSTimer!

  9. Swift 使用CollectionView 实现图片轮播封装

    前言:这篇你可以学会自定义视图,创建collectionView,协议的使用,定时器;首先新建一个继承于UIView的视图,且用collectionView实现所以需要签订两个协议代码如下:使用到的变量以及创建视图布局必要的UI以及创建定时器定时器初始化销毁定时器实现循环滚动collectionViewDelegate设置当前的pagecontrol点击方法下面是我在自定义cell中的代码封装基本

  10. Swift 项目首次启动轮播页的制作

    最近利用休息时间在模仿一点停的项,使用Swift写的。一般我们项目在安装后的第一次启动都会有一个左右滑动的轮播页,一般是关于app的宣传页面或是介绍或是广告。找思路之前先要分析需求:1.安装后首次启动app的时候回有这个轮播页2.左后滑动……也就是说,只要运行过IndexViewController之后,这个键值对有始终会存在一个值,那么app以后的启动就不会进入IndexViewController,而是默认的ViewController。IndexViewController制作轮播页/切换跟控制器/

随机推荐

  1. js中‘!.’是什么意思

  2. Vue如何指定不编译的文件夹和favicon.ico

    这篇文章主要介绍了Vue如何指定不编译的文件夹和favicon.ico,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  3. 基于JavaScript编写一个图片转PDF转换器

    本文为大家介绍了一个简单的 JavaScript 项目,可以将图片转换为 PDF 文件。你可以从本地选择任何一张图片,只需点击一下即可将其转换为 PDF 文件,感兴趣的可以动手尝试一下

  4. jquery点赞功能实现代码 点个赞吧!

    点赞功能很多地方都会出现,如何实现爱心点赞功能,这篇文章主要为大家详细介绍了jquery点赞功能实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  5. AngularJs上传前预览图片的实例代码

    使用AngularJs进行开发,在项目中,经常会遇到上传图片后,需在一旁预览图片内容,怎么实现这样的功能呢?今天小编给大家分享AugularJs上传前预览图片的实现代码,需要的朋友参考下吧

  6. JavaScript面向对象编程入门教程

    这篇文章主要介绍了JavaScript面向对象编程的相关概念,例如类、对象、属性、方法等面向对象的术语,并以实例讲解各种术语的使用,非常好的一篇面向对象入门教程,其它语言也可以参考哦

  7. jQuery中的通配符选择器使用总结

    通配符在控制input标签时相当好用,这里简单进行了jQuery中的通配符选择器使用总结,需要的朋友可以参考下

  8. javascript 动态调整图片尺寸实现代码

    在自己的网站上更新文章时一个比较常见的问题是:文章插图太宽,使整个网页都变形了。如果对每个插图都先进行缩放再插入的话,太麻烦了。

  9. jquery ajaxfileupload异步上传插件

    这篇文章主要为大家详细介绍了jquery ajaxfileupload异步上传插件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  10. React学习之受控组件与数据共享实例分析

    这篇文章主要介绍了React学习之受控组件与数据共享,结合实例形式分析了React受控组件与组件间数据共享相关原理与使用技巧,需要的朋友可以参考下

返回
顶部