Blinky Javascript



  • How would you make an element "blink" with JavaScript and jQuery?

    Some of you might say http://api.jquery.com/animate/

    others might say.....

    window.setTimeout(function(){
                $("#AttestationNag").css('background','');
                window.setTimeout(function(){
                    $("#AttestationNag").css('background','#EFC1CE');
                    window.setTimeout(function(){
                        $("#AttestationNag").css('background', '');
                        window.setTimeout(function(){
                            $("#AttestationNag").css('background', '#EFC1CE');
                            window.setTimeout(function() {
                                $("#AttestationNag").css('background', '');
                                window.setTimeout(function() {
                                    $("#AttestationNag").css('background', '#EFC1CE');
                                    window.setTimeout(function() {
                                        $("#AttestationNag").css('background', '');
                                        window.setTimeout(function(){
                                            $("#AttestationNag").css('background', '#EFC1CE');
                                            window.setTimeout(function() {
                                                $("#AttestationNag").css('background', '');
                                                window.setTimeout(function() {
                                                    $("#AttestationNag").css('background', '#EFC1CE');
                                                    window.setTimeout(function() {
                                                        $("#AttestationNag").css('background', '');
                                                    }, 400);
                                                }, 400);
                                            }, 400);
                                        }, 400);    
                                    }, 400);
                                }, 400);
                            }, 400);
                        }, 400);   
                    },400);
                },400);
            },400);
    


  •  Haha, I like!



  • Oh wow. Surely after the first few lines you'd stop and think that there's a better way to do it. o_o



  •  I think I would usually say, "WHY ARE YOU ASKING ME TO REINVENT THE <BLINK> TAG?!?!?!"



  • @vt_mruhlin said:

    THE <BLINK> TAG
    This is like a blink tag that has controllable speed, controllable colours, and blinks only for a certain amount of time. It's like an <AWESOME-BLINK> tag. Prepare for the revolution!



  • Indeed, for all its WTFery, this has one major advantage over most blink implementations I've seen:

    It stops after 4.4 seconds.



  • @Daniel15 said:

    Oh wow. Surely after the first few lines you'd stop and think that there's a better way to do it. o_o

    Yeah, it should be in a function so that you can add more blinks without adding to the nested function call.



  • @toth said:

    @Daniel15 said:
    Oh wow. Surely after the first few lines you'd stop and think that there's a better way to do it. o_o

    Yeah, it should be in a function so that you can add more blinks without adding to the nested function call.

     

    It should use setInterval.

    BEHOLD! Code for a timed for-loop. 

       var arry = new Array(42);
       var i = 0;
       var loopTimer = setInterval(function () {
          if (i == arry.length) {
             clearInterval(loopTimer);
             return;
          }
          /////

          //your shit with i.

          /////
          i++;
       }, 250);

     

    I have given you a clean BLINK. Use it wisely.



  • Do I have to be the one to point out that the code is actually using jQuery?

     



  • @Zecc said:

    Do I have to be the one to point out that the code is actually using jQuery?
     

    Correction; it is barely using jQuery. It might as well not be using jQuery. It's written, or generated, by someone who has absolutely no interest in writing jQuery, or perhaps Javascript at all.



  • @vyznev said:

    Indeed, for all its WTFery, this has one major advantage over most blink implementations I've seen:

    It stops after 4.4 seconds.

     

    Still 4.3999 sec too late, but a major win anyway.



  • @Daniel15 said:

    Oh wow. Surely after the first few lines you'd stop and think that there's a better way to do it. o_o
    The Real JavaScript Way™ is of course to make a loop that replicate the pattern a LOT of times in a string, and then eval it.



  • @eBusiness said:

    @Daniel15 said:
    Oh wow. Surely after the first few lines you'd stop and think that there's a better way to do it. o_o
    The Real JavaScript Way™ is of course to make a loop that replicate the pattern a LOT of times in a string, and then eval it.

    Surely the real solution is to use the Y combinator. (I'd write such a version, but I don't know JavaScript.)



  • @Spectre said:

    @eBusiness said:
    @Daniel15 said:
    Oh wow. Surely after the first few lines you'd stop and think that there's a better way to do it. o_o
    The Real JavaScript Way™ is of course to make a loop that replicate the pattern a LOT of times in a string, and then eval it.

    Surely the real solution is to use the Y combinator. (I'd write such a version, but I don't know JavaScript.)

    Two possible answers:

    1. I don't see why you'd need to fund a startup to solve such a simple problem.
    2. I know JavaScript, but on the other hand I'm sane.



  • Looks like I'm not that sane after all:

    <font face="courier new,courier">function Y(f) {
        return function(){
            var args = [f].concat(Array.prototype.slice.call(arguments));
            return f.apply(null, args);
        }
    }</font>

    <font face="courier new,courier">Y(function(f, t, on){
        $("#AttestationNag").css('background', on ? '#EFC1CE' : '');
        t -= 400;
        if (t > 0){
            setTimeout( function(){ f(f, t, !on); }, 400);
        }
    })(4400, false);</font>



  • @b-redeker said:

    @vyznev said:

    Indeed, for all its WTFery, this has one major advantage over most blink implementations I've seen:

    It stops after 4.4 seconds.

     

    Still 4.3999 sec too late, but a major win anyway.

     

    If only we could live in a world where all pointless annoying things stopped after 4.4 seconds.

    (This would be a good time to break out the rainbows and unicorns, I think....)



  • @da Doctah said:

    If only we could live in a world where all pointless annoying things stopped after 4.4 seconds.

    It would be a world covered in the corpses of flies.



  • @Faxmachinen said:

    @da Doctah said:

    If only we could live in a world where all pointless annoying things stopped after 4.4 seconds.

    It would be a world covered in the corpses of flies.

    Makes me wonder what chance of survival humanity would have?


  • @Faxmachinen said:

    @da Doctah said:

    If only we could live in a world where all pointless annoying things stopped after 4.4 seconds.

    It would be a world covered in the corpses of flies.

     

    You say "corpses of flies", I say "lizard chow".  There's always a silver lining.



  • @da Doctah said:

    @Faxmachinen said:

    @da Doctah said:

    If only we could live in a world where all pointless annoying things stopped after 4.4 seconds.

    It would be a world covered in the corpses of flies.

     

    You say "corpses of flies", I say "lizard chow".  There's always a silver lining.



  • @dhromed said:

    @Zecc said:

    Do I have to be the one to point out that the code is actually using jQuery?
     

    Correction; it is barely using jQuery. It might as well not be using jQuery. It's written, or generated, by someone who has absolutely no interest in writing jQuery, or perhaps Javascript at all.

    Considering it doesn't use a basic construct like a for-loop, I'd have to go with the last option.



  • @PeriSoft said:

     

     

    Why does something that's omnivorous need special food?



  • @RTapeLoadingError said:

    @PeriSoft said:

     

     

    Why does something that's omnivorous need special food?

     

    Other food doesn't have "everything" in it. Or Mormans.



  • @RTapeLoadingError said:

    Why does something that's omnivorous need special food?

    Duh! It's the "LIZARD<font size="-2">FOOD</font>" which is obviously omnivorous.



  • @RTapeLoadingError said:

    @PeriSoft said:

     

     

    Why does something that's omnivorous need special food?

    It doesn't need special food, but there is food meant specifically for them because they're omnivorous and will eat stuff no other living thing wants.



  •  So we have,

    Option A: The can contains food made from everything

    @Zemm said:

    Other food doesn't have "everything" in it. Or Mormans.
     

     

    Option B: The can contains food made from the stuff no other living creature would eat

    @Zecc said:

    It doesn't need special food, but there is food meant specifically for them because they're omnivorous and will eat stuff no other living thing wants.

     

    Option C: It's a can containing a blend of <font size="-2">LAND</font> TORTOISE & OMNIVOROUS LIZARD<font size="-2">FOOD</font>

    @Anonymouse said:

    Duh! It's the "LIZARD<font size="-2">FOOD</font>" which is obviously omnivorous.
     

     

    My money's on option B


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.