简体   繁体   English

我可以在网页上劫持垂直滚动动作并将其水平移动吗?

[英]On a webpage can I hijack the vertical scrolling action and make it horizontal?

On a webpage can I hijack the vertical scrolling action and make it horizontal? 我可以在网页上劫持垂直滚动动作并将其水平移动吗?

Please try and ignore the potential usability issues. 请尝试忽略潜在的可用性问题。

On a webpage can I hijack the vertical scrolling action and make it horizontal? 我可以在网页上劫持垂直滚动动作并将其水平移动吗?

Not as far as I know (except maybe by rotating the element - but that is probably not what you want). 据我所知(除非可能通过旋转元素-但这可能不是您想要的)。

You would have to re-arrange the contents to make the vertical scroll bar go away, and force a horizontal one instead. 您必须重新排列内容,以使垂直滚动条消失,而强制水平滚动条。

Whether that is possible will strongly depend on the nature of the HTML elements inside the page. 是否可行在很大程度上取决于页面内HTML元素的性质。

Yes you can do this. 是的,您可以这样做。

Vertical scrolling is set to element.scrollTop 垂直滚动设置为element.scrollTop

You could simply add a loop that catches scrollTop when it changes, sets it back to zero and then sets the scrollLeft to be = to the changed position. 您可以简单地添加一个循环,在它更改时捕获scrollTop,将其设置回零,然后将scrollLeft设置为=到更改的位置。

More so, an even better solution is to overwrite the onscroll event. 更重要的是,一个更好的解决方案是覆盖onscroll事件。

window.onscroll = function(event){

 event.preventDefault() // Stops the page from scrolling vertically.


 window.scrollLeft = event.scrollTop // This is not the correct event attribute, youll have to locate it yourself.
}

这是一个执行此操作的jQuery插件,您可以将其指定为仅在鼠标悬停在目标元素上时才起作用: http : //flowplayer.org/tools/scrollable/index.html

You could hook into the scroll event, check which plane is being scrolled, if it was the vertical then set the difference as the horizontal scroll and set the vertical scroll to it's previous value. 您可以关联到滚动事件,检查正在滚动的平面,如果它是垂直平面,则将差异设置为水平滚动,并将垂直滚动设置为其先前的值。 Though I can imagine that would be incredibly expensive. 虽然我可以想象这将是非常昂贵的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM