2011-10-13 40 views
0

例如,當我從答案中複製鏈接並訪問該鏈接時,出現一個很好的顏色塊以突出顯示答案,然後淡出。這是如何完成的?淡化色彩答案技巧

+0

的[使用jQuery你如何淡入/淡出背景顏色?(可能重複http://stackoverflow.com/questions/ 967815 /你怎麼做 - 淡入淡出背景色 - 使用jquery)...請在提問之前使用搜索。 –

+0

使用你的想象力和螢火蟲。 –

回答

3

它看着散列,選擇那個答案,然後動畫背景顏色。要麼使用jQuery UI,要麼添加Colors plugin以便能夠爲動畫顏色添加動畫。

這是該代碼可能是什麼樣子......

var hash = window.location.hash; 

if (hash) { 
    var answer = $('#answer-' + hash.substr(1)), 
     originalBackgroundColor = answer.css('backgroundColor'); 

    // This class changes the background colur. 
    // Best to keep style stuff in the CSS layer. 
    answer 
    .addClass('linked') 
    .animate({ 
     backgroundColor: originalBackgroundColor 
    }, 1000); 

    // You may optionally remove the added class 
    // in the callback of the above animation. 
}