0%

Js 上下滚动改为左右滚动

这个方法非常巧妙,把滚动条上下滚动改为了左右移动

https://dev.to/juanbelieni/how-to-create-horizontal-scroll-with-mouse-wheel-using-javascript-4cm5
https://css-tricks.com/snippets/jquery/horz-scroll-with-mouse-wheel/
https://stackoverflow.com/questions/11700927/horizontal-scrolling-with-mouse-wheel-in-a-div
https://stackoverflow.com/questions/12916289/how-to-trigger-javascript-mouse-scroll-wheel-on-a-divs-horizontal-scrollbar

1
2
3
4
5
6
7
8
9
let element = document.querySelector('.recommendation-content');

element.addEventListener('wheel', (event) => {
event.preventDefault();

element.scrollBy({
left: event.deltaY < 0 ? -30 : 30,
});
});

参考资料

https://www.zhangxinxu.com/wordpress/2013/04/js-mousewheel-dommousescroll-event/
https://www.zhangxinxu.com/study/201304/mousewheel-event-image-slide.html
https://blog.csdn.net/hbiao68/article/details/104916017
https://blog.csdn.net/chenyinquan9211/article/details/80603721