淡出色彩答案技巧

时间:2011-10-13 06:39:19

标签: javascript jquery fadeout

例如,当我从答案中复制链接并访问它时,一个漂亮的颜色块似乎突出显示答案,然后逐渐消失。怎么做的?

1 个答案:

答案 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.
}