javascript 当光标位于div边缘时如何滚动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11222047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 12:26:05  来源:igfitidea点击:

How to scroll when cursor is on the edge of div?

javascriptjqueryhtmlcss

提问by Farhad-Taran

I have a div(menubar) that has a lot of links and these links are out of the view. I must make the div scroll to the right or left when the cursor is at the edge of the menu div, in order to bring these menu items into the view. enter image description here

我有一个 div(menubar) 有很多链接,这些链接不在视图中。当光标位于菜单 div 的边缘时,我必须使 div 向右或向左滚动,以便将这些菜单项带入视图中。 在此处输入图片说明

I am a beginner with Jquery, so any help is greatly appreciated.

我是 Jquery 的初学者,因此非常感谢任何帮助。

Markup is in Jsfiddle

标记在 Jsfiddle 中

回答by BalaKrishnan?

Take a look at this example, in this example you can see how they scroll the div when the mouse at right edge of the div. you can do the same thing.

看一下这个例子,在这个例子中你可以看到当鼠标在 div 的右边缘时它们是如何滚动 div 的。你可以做同样的事情。

How to Auto Scroll a div on mouse move over the margins?

如何在鼠标移过边距时自动滚动 div?

回答by Vinoth Kumar

Here Answer

这里回答

<div onmouseover="this.className='addscrool'"    onmouseout="this.className='removescrool';" style="width:100px;height:100px;border:1px  solid Blue">
 </div>
 <style>
.addscrool
{
overflow-y: scroll;
}   .removescrool
{
overflow-y:hidden ;
 }