【问题标题】:Detect mousedown/click event on browser's scrollbar检测浏览器滚动条上的 mousedown/click 事件
【发布时间】:2016-04-20 16:07:55
【问题描述】:

我知道使用 jQuery 表达式 $(element).on("mousedown", function(evt) { ... }); 您可以处理元素上的 mousedown 事件。

虽然我需要检测浏览器滚动条上的mousedownclick事件并且需要运行一些功能。

【问题讨论】:

标签: javascript jquery


【解决方案1】:

我建议捕获 mousedown 事件并测试坐标。如果坐标大于或等于可见文档正文宽度,则在滚动条区域单击!

$(document).ready(function() {
  $(document).mousedown(function(event) {
    if(event.target === $('html')[0] && event.clientX >= document.documentElement.offsetWidth)
      alert('vertical scrollbar clicked');
  })
})

【讨论】:

    猜你喜欢
    • 2011-04-17
    • 2015-04-11
    • 2010-09-06
    • 2010-11-17
    • 1970-01-01
    • 2018-08-31
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多