延迟链接点击 [英] Delay a link click
问题描述
以下是我正在使用的小提琴: http://jsfiddle.net/Scd9b/
Here's the fiddle I'm working with: http://jsfiddle.net/Scd9b/
如何在点击后延迟href功能?
How can I delay the href function after the click?
例如用户点击链接,消息向下滑动一会儿...... 并在2秒后用户继续浏览其链接的页面。
For example a user clicks on the link, the message slides down One moment... and after 2 seconds the user continues to the page its linked to.
抱歉,每个人都忘记提及有一些未链接的锚点。
Sorry everybody forgot to mention there are some anchors that are not linked.
推荐答案
您可以通过设置window.location模拟导航到页面。因此我们将使用 preventDefault
阻止链接的正常功能,然后在 setTimeout
中,我们将设置正确的窗口.location:
You can simulate navigating to a page by settings window.location. So we will block the normal function of the link with preventDefault
and then in a setTimeout
, we will set the correct window.location:
https:// codepen。 io / anon / pen / PePLbv
$("a.question[href]").click(function(e){
e.preventDefault();
if (this.href) {
var target = this.href;
setTimeout(function(){
window.location = target;
}, 2000);
}
});
这篇关于延迟链接点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!