标签:div title var add javascrip htm return event list
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
#box-small {
width: 1000px;
height: 2000px;
}
#box{
width: 100%;
height: 500px;
/*overflow: hidden;*/
overflow: auto;
}
</style>
</head>
<div id="box">
<div id="box-small">0.0</div>
</div>
<body>
<!-- vue监听滚动事件 -->
<script type="text/javascript">
var vm = new Vue({
el:‘#box‘,
data() {
return {
scrollLeft: ‘‘,
scrollTop: ‘‘,
}
},
methods: {
menu(e) {
console.log(e);
this.scrollLeft = document.getElementById(‘box‘).scrollLeft;
this.scrollTop = document.getElementById(‘box‘).scrollTop;
console.log(this.scrollTop);
console.log(this.scrollLeft);
}
},
mounted() {
var obj = document.getElementById(‘box‘);
obj.addEventListener(‘scroll‘, this.menu)
},
})
</script>
</body>
</html>
Vue没有scroll事件所以要用原生的写,并且写在周期函数mounted里
标签:div title var add javascrip htm return event list
原文地址:https://www.cnblogs.com/yuyouyi/p/9286686.html