Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  104] [ 1]  / answers: 1 / hits: 18535  / 13 Years ago, sun, january 8, 2012, 12:00:00

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, 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.


More From » jquery

 Answers
49

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

[#88167] Friday, January 6, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micayla

Total Points: 148
Total Questions: 92
Total Answers: 109

Location: Aruba
Member since Sat, Oct 2, 2021
3 Years ago
micayla questions
Fri, Dec 24, 21, 00:00, 2 Years ago
Thu, Apr 16, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
;