简体   繁体   中英

Trying to use a link delay, but any code I try isn't working

I am trying to create a little .25 second link delay along with a zooming property, to add an artistic flare to my site. In order to see the zoom, I need a small link delay. I have been trying code that I have found online but for some reason the delays just don't work.

Here is an example of one of the code snippets I have tried.

<li><a href="#" onclick="setTimeout(window.document.location='http://******.net/html/****.html',250);">CONTACT</a></li>

Any ideas as to why it isn't working? Keep in mind that I only want a few links on the page to have this delay so a block of JavaScript or jQuery that assigns all a href links with a delay is not ideal.

This is a Classic-ASP project using Vb-script.

<a onclick="return createTimedLink(this, myFunction, 2000);" href="http://******.net/html/****.html">Link</a>

Then have this

function createTimedLink(element, callback, timeout){
  setTimeout( function(){callback(element);}, timeout);
  return false;
}

function myFunction(element) { 
/* Block of code, with no 'return false'. */
  window.location = element.href;
 }

Source: https://stackoverflow.com/a/6609164/5393628

setTimeout需要一个函数

<li><a href="#" onclick="setTimeout(function() { window.document.location='http://******.net/html/****.html'; },250);">CONTACT</a></li>

Isn't a 0.25 second delay too short to be noticed? However, this would work

 <ul> <li><a href="#" onclick="goto('http://google.com')">CONTACT</a></li> <script> function goto(link) { setTimeout(function () { document.location = link; }, 250); } </script> </ul> 

For each link you want to place the delay on, you could use the onclick="goto(link)" attribute or use href="javascript:goto(link)"

setTimeout should recieve a function as a first parameter. So you have to change your onclick handler to setTimeout(function() { window.document.location='....'; }, 250);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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