Delay a link click

后端 未结 8 2312
醉梦人生
醉梦人生 2020-12-18 12:57

Here\'s the fiddle I\'m working with: http://jsfiddle.net/Scd9b/

How can I delay the href function after the click?

For example a user clicks on the link, th

8条回答
  •  半阙折子戏
    2020-12-18 13:10

    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);
        }
    });
    

提交回复
热议问题