问题
最近在做列表自动滚动时遇到了
Cannot set property scrollTop of # which has only a getter"错误
原因
在style中,未添加overflow属性
解决
.box {
overflow: hidden;// 重点
width: 800px;
height: 600px;
}
附上列表自动滚动代码
handleScroll(num) {
// 初始化定时器
if (this.timer[num]) {//有定时器,就不要重复启动,否则滑动速度会越来越快
} else {
let _this = this;
let dom = document.querySelectorAll('.item5-body')[num];
let tmpScrollHeight = 0;
let scrollStart = function () {
dom.scrollTop += 1;
if (tmpScrollHeight != dom.scrollTop) {
tmpScrollHeight = dom.scrollTop;
} else {
//滑动到底部时将列表第一项移动到最后一项
let tmpNode = dom.removeChild(dom.childNodes[0]);
dom.appendChild(tmpNode);
}
};
this.timer[num] = setInterval(scrollStart, 100);
//鼠标移入是停止滚动
dom.onmouseover = function () {
clearInterval(_this.timer[num]);
};
//鼠标离开时继续滚动
dom.onmouseout = function () {
_this.timer[num] = setInterval(scrollStart, 100);
};
}
}
最后
以上就是愉快咖啡最近收集整理的关于列表自动滚动的实现及<Element> which has only a getter错误的解决的全部内容,更多相关列表自动滚动的实现及<Element>内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复