简体   繁体   English

在<a>鼠标按下而不是鼠标点击时</a>跟随<a>链接</a>

[英]Following <a> links on mouse down instead of on mouse click

I am using the following code to make the browser follow a link on mouse down instead of on mouse up (like a normal click).我使用以下代码使浏览器在鼠标按下而不是鼠标抬起时跟随链接(如正常单击)。

$('#links a').each(function(){
  $(this).mousedown(function(){
    window.location.href=$(this).attr('href');
  });
});

First of all, is this good practice?首先,这是好的做法吗? GMail does this and it gives the effect that the page is loading faster than it actually is. GMail 执行此操作并产生页面加载速度比实际速度更快的效果。

Also, is there a better way of doing this?另外,有没有更好的方法来做到这一点? I haven't tested this in all browsers yet, so I'm not sure if it works in older browsers.我还没有在所有浏览器中测试过这个,所以我不确定它是否适用于旧浏览器。

The mousedown function is not supported by Internet Explorer version 5.5 or earlier. Internet Explorer 5.5或更早版本不支持mousedown功能。 jQuery normalizes the browser-specific behavior of the event capture into the mousedown function. jQuery 将事件捕获的浏览器特定行为规范化为mousedown函数。

As to good practice or not, I don't see a tangible performance benefit from handling mouse click events in this way.至于好的做法与否,我没有看到以这种方式处理鼠标点击事件有明显的性能优势。 So, unless you have a specific reason for doing so, I would stay with standard conventions.所以,除非你有特定的理由这样做,否则我会坚持标准约定。

The only thing that should happen on mouse down is any necessary effects to show the user the mouse button is indeed down.鼠标按下时唯一应该发生的事情是向用户显示鼠标按钮确实按下的任何必要效果。

The reason you don't execute anything until mouse up goes back to at least the Apple Human Interface Guidelines for the original Macintosh: This gives the user the option of "canceling" their click by moving the mouse off the button before letting go.在鼠标抬起之前不执行任何操作的原因至少可以追溯到原始 Macintosh 的 Apple 人机界面指南:这使用户可以选择“取消”单击,方法是在松开鼠标之前将鼠标从按钮上移开。

Doing things on mouse down will give the user the sense that your program is pulling the rug, er, dialog box out from under them.在鼠标按下时做事情会让用户感觉你的程序正在从他们下面拉出地毯,呃,对话框。

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

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