0

I am trying to get some flashing effect by jQuery. Please help. Here is the not-working code.

Javascript:

jQuery(document).ready(function(){
     var flashThis = function(){
        var className = $('#annoying').attr('class');
        if(className.indexOf("blueOne") !== -1) {
           jQuery("#annoying").removeClass("blueOne");
        }
        if(className.indexOf("blueOne") === -1) {
           jQuery("#annoying").addClass("blueOne");
        }
        flashThis();
     }

     flashThis();
  });

CSS:

   .whiteOne {
      color:#FFFFFF;
   }
   .blueOne {
      color:#0000FF;
   }

HTML:

<p id="annoying" class="whiteOne">I will flash.</p>

4

2 回答 2

2

试试这个:

setInterval(function () {
    $('#annoying').toggleClass('whiteOne blueOne');
}, 500);

jsFiddle 示例

于 2013-11-05T19:25:57.230 回答
0

Even simpler HTML, CSS and JS:

LIVE DEMO

<p id="annoying">I will flash.</p>

#annoying {
  color:#0000FF;
}

(function flash(){
 $('#annoying').delay(300).toggle(0, flash);
}());
于 2013-11-05T19:38:35.153 回答