项目要求滚动条自定定位到最右(突然发现typora收费了,这里记录一下)
1.使用getElementsByClassName拿到所有有滚动条的盒子,注意这里的返回值是一个类数组,类数组的使用不能直接使用数组的方法,需要使用Array.prototype.forEach.call(返回值,func(这里处理类数组里面的数据))
2.使用scrollTo(left,top),可以移动滚动条,left表示距离滚动条最左边边界有多少,直接使用数字就可以,不要加上px;
伪代码如下:
autoRight(){
let container = document.getElementsByClassName("lzx");
Array.prototype.forEach.call(container,(item) =>{
if(item.scrollWidth > 1019){
item.scrollTo(10,0)
}
})
}