2013-01-14 58 views
0

我想知道是否有人有任何延遲的經驗?我試圖讓我所有的全球鏈接打開一段時間。只是爲了給它一個藝術效果,使它更平滑地交換頁面。但由於某種原因,我無法得到它的工作。我會很感激我能得到的任何幫助。如何給我所有的網頁鏈接打開延遲?

HTML:

<!DOCTYPE html> 
<html lang="en-US"> 
    <head> 
    <meta charset="utf8" /> 
     <link rel="stylesheet" type="text/css" media="all" href="css/mainstyle.css"/> 
     <meta name="viewport" content="initial-scale=1" /> 
     <title> Redneck Rampage </title> 
    </head> 
    <body class="filter"> 
    <div id="background"> 
     <div id="wrapper"> 
      <div class="navigation"> 
       <ul id="mainmenu"> 
        <li class="active"><a href="index.html">Home</a></li> 
      <li><a href="band.html">Band</a></li> 
      <li><a href="news.html">News</a></li> 
        <li><a href="shows.html">Shows</a></li> 
        <li><a href="music.html">Music</a></li> 
        <li><a href="gallery.html">Gallery</a></li> 
        <li><a href="media.html">Media</a></li> 
        <li><a href="store.html">Store</a></li> 

       </ul> 
      </div> 

       <div class="footer homepage"> 
        <p class="rednecks">Website and Contents &copy; Redneck Rampage 2013. </p> 
        <p class="signature">Designed by Martin Metsalu </p> 

         <ul id="footermenu"> 
          <li><a href="terms.html">Terms of use</a></li> 
          <li><a href="privacy.html">Privacy Policy</a></li> 
          <li><a href="contact.html">Contact</a></li> 
         </ul> 
        <div class="socialplugins"> 
         <div class="test"><a href="#"><img src="IMG/soundcloud.png" alt="plugin#1" ></a></div>   
         <div class="test"><a href="#"><img src="IMG/youtube.png" alt="plugin#2"></a></div> 
         <div class="test"><a href="#"><img src="IMG/myspace.png" alt="plugin#3"></a></div> 
         <div class="test"><a href="#"><img src="IMG/facebook.png" alt="plugin#4"></a></div> 

        </div> 

       </div> 
     </div> 
    </div> 
</body> 
</html> 

JQUERY:

 $('a').click(function(e) { 
$('a[href*="/steve"]').each(function(index) { 
    setTimeout(
     function(href){window.open(href)}, 
     (index+1)*5000, $(this).attr('href') 
    ); 
}); 
+1

在setTimeout之後添加'return false'。 – Malk

+2

你究竟想要做什麼?當用戶點擊鏈接時,您希望點擊事件被延遲?或者您只希望頁面每5秒鐘連續開始在新窗口中打開?從代碼和描述來看,它看起來像是在嘗試做其中的一種,無論哪種方式都是*糟糕的可用性選擇。 –

+0

我想,因爲一些頁面比其他頁面包含更多的內容,我給他們一個時間延遲(不需要5秒)。但我想這隻會延遲執行點擊命令。在此之後,內容仍然需要時間加載,對嗎?如果是這樣,我如何預先加載內容以使網絡體驗更少機械。 – Laniakea

回答

1
$('a[href*="/steve"]').each(function() { 
    $(this).on('click', function (event) { 
     event.preventDefault(); 
     (function (h) { 
      setTimeout(function() { 
       window.location = h; 
      }, 5000); 
     })(this.href); 
    }); 
}); 

給出的頂部做e.preventDefault();那一試。

+0

試一試。沒有得到任何結果。這裏是我的代碼的標記:https://github.com/ISynesthesiaI/Stack-Overflow – Laniakea

+0

哦,我忘了添加一個額外的「星」符號。替換第一行代碼:** $('a [href * =「*。html」]').each(function(){**感謝幫助! – Laniakea

0

我想你只需要在你的點擊功能