jQuery 使用垂直滚动条和 mousedown - FireFox 有效,IE 有问题
我有一个用 jQuery 编写的菜单,当事件触发时会弹出。它的侧面有一个垂直滚动条。滚动在 FireFox 中工作正常,但在 IE(8 或 9)中不行。我想这与 mousedown 事件有关,需要从菜单中选择一个项目。
.mousedown(function (event) {
var li = get_element_from_event(event, "li");
if(li){
return false;
}
对于 IE,当用鼠标单击滚动条时,菜单会再次折叠(就像用户进行了选择一样)。
这是 IE 中的常见问题(即滚动条问题)吗?
我认为这也与以下滚动条代码片段有关
$(".token-input-list")[0].scrollTop = $(".token-input-list")[0].scrollHeight;
I have a menu scripted with jQuery, which pops out when triggered by an event. It has a vertical scroll bar on the side. The scrolling works fine in FireFox, but not in IE (8 or 9). I guess it has something to do with the mousedown
event, which is needed to select an item from the menu.
.mousedown(function (event) {
var li = get_element_from_event(event, "li");
if(li){
return false;
}
In case of IE, when clicking with the mouse on the scrollbar, the menu collapses again (as if the user made a selection).
Is this a common problem in IE (i.e. issues with the scrollbar)?
I think it also has to do with the following snippet of scrollbar code
$(".token-input-list")[0].scrollTop = $(".token-input-list")[0].scrollHeight;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据
get_element_from_event()
的作用以及您使用mousedown
执行的其他操作,IE 可能会正确运行 - 如果事件目标不是元素,它会据说li
返回 false,因此if(li)
会失败,因此mousedown
不会返回 false,但继续前进。至于修复它,您需要找出 IE 为
li
返回的内容(通过警报或控制台),并在get_element_from_event()
中对其进行测试> 或在新的变量/函数中。Depending on what
get_element_from_event()
does, and what else you're doing withmousedown
, IE may be behaving correctly--if the event target is not an element, it will supposedly return false forli
, and so it will failif(li)
and therefore not return false formousedown
, but keep on chugging along.As far as fixing it goes, you'll want to find out what IE is returning for
li
(via an alert or the console) and either test for it inget_element_from_event()
or in a new var/function.如果您的 .mousedown 事件附加到滚动条所在的同一元素,请将您的 .mousedown 事件移动到具有滚动条的 div 内的新 div。
If your .mousedown event is attached to the same element the scrollbar is on, move your .mousedown event to a new div inside the div that has the scrollbar.
感谢您的输入 - 我发现滚动条问题上有很多错误,因此我通过包含在这里找到的一个不错的列表脚本来解决它: http://rascarlito.free.fr/hoverscroll/。这对 IE 来说是个窍门,对我来说也是如此;)
Thanks for your input - I found quite a bit of buggyness on the scrollbar issue, so I solved it by inlcuding a nice list script found here: http://rascarlito.free.fr/hoverscroll/. Dit the trick for IE, and thus for me ;)
问题是使用全局window.event对象,而不是jQuery的事件对象。 window.event 仅适用于某些浏览器,并且它不是 W3C 标准。
jQuery 规范化了事件对象,因此它在所有浏览器中都是相同的。事件处理程序将该 jQuery 事件对象作为参数传递。使用那个。
The problem is that using the global window.event object, and not jQuery's event object. window.event only works in some browsers, and it is not a W3C standard.
jQuery normalizes the event object so it's the same in all browsers. The event handler is passed that jQuery event object as a parameter. using that.