._vue div滚动">
当前位置:   article > 正文

vue实现div向上滚动_vue div滚动

vue div滚动

在这里插入图片描述

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
	<style>
		.box{
			height: 100px;
			overflow: hidden;
		}
	</style>
</head>
<body>
	<div id="app">
		<div ref="box" class="box">
			<div ref="items1" class="items">
				<div class="item" v-for="item in items" :key="item">{{item}}</div>
			</div>
			<div ref="items2" class="items2"></div>
		</div>
	</div>
	<script src="./node_modules/vue/dist/vue.js"></script>
	<script>
		new Vue({
			el:'#app',
			data(){
				return{
					items:[1,2,3,4,5,6,7]
				}
			},
			mounted(){
				this.setScroll();
			},
			methods:{
				setScroll(){
					let box= this.$refs.box;
					let items1 = this.$refs.items1;
					let items2 = this.$refs.items2;
					items2.innerHTML=items1.innerHTML;
					
					function Marquee(){
					    if(box.scrollTop >= items1.offsetHeight){
							box.scrollTop=0;
					    }else{
							box.scrollTop++;
					    }
					}
					  var MyMar=setInterval(Marquee,40)
					  box.onmouseover=function(){clearInterval(MyMar)}
					  box.onmouseout=function(){MyMar=setInterval(Marquee,40)}
				}
			}
		})
	</script>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号