2013-11-21 33 views

回答

0

我在下面的方式

$(document).ready(function(){ 
       if(document.location.href.indexOf('#') > -1){ 
        var id = location.hash.replace("#",""); 
        $thisAns = $("#"+id); 
        $thisAns.addClass("highlightAns"); 
         // Remove that class after 2 seconds      
         setTimeout(function(){ 
          $thisAns.removeClass("highlightAns"); 
         },2000); 
       } 
       else{ 
        console.log("URL does not contains Id"); 
       }  

       $('.highlight').on('click', function() { 
        // Get the div that should be higlighted now 
        var id = $(this).attr('href').replace("#", ""); 
        $thisAns = $('#'+id); 
        // Add highlightAns class 
        $thisAns.addClass("highlightAns"); 
        // Remove that class after 2 seconds      
        setTimeout(function(){ 
         $thisAns.removeClass("highlightAns"); 
        },2000); 
       }); 
     }); 
0

試試這個:

 // Add highlightAns class 
     $thisAns.addClass("highlightAns").fadeIn("slow"); 

    // Remove that class after 2 seconds      
     setTimeout(function(){ 
      $thisAns.removeClass("highlightAns").fadeOut("slow"); 
     },2000); 

Demo

2

你的意思是這樣的?它淡入淡出。

jsFiddle

給了所有的答案一類answers和I類給CSS transition:2s;這是多麼漫長的類添加和刪除需要。

+0

工作正常,但如果我複製鏈接地址爲我的情況(http:// localhost:8080 /測試/ ques.jsp#Faq5)到另一個瀏覽器選項卡,然後它不會褪色.. –

+0

它不會褪色,因爲你需要再次點擊鏈接,它是在點擊問題時觸發的。 @Sumit – Albzi