1、scroll事件不能阻止默认动作
阻止scroll默认动作没用,因为先有滚动,才有滚动事件
要阻止滚动,可阻止wheel和touchstart的默认动作
注意你需要找准滚动条所在的元素
但是滚动条还能用,可用CSS让滚动条width:0
代码链接:http://js.jirengu.com/luwus/1/edit?html,css,js,output
<!DOCTYPE html><html><head><meta charset="utf-8"><title>JS Bin</title><style>::-webkit-scrollbar {width:0 !important}</style></head><body><div id=x><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p></div></body></html>
x.addEventListener('wheel',(e)=>{e.preventDefault()})//x.addEventListener('touchstart',(e)=>{//e.preventDefault()//})
2、CSS也行
使用overflow:hidden可以直接取消滚动条
但此时JS依然可以修改scrollTop
