jquery - Javascript falling letters: Every other letter different direction -


i'm having hard time finding way insert falling letters code. task have text string , have even-placed letters fall top , odd-placed letters fly bottom , come form string in center.

so instance, have: <span class="uname">john doe</span>

i letters: o, n, d, e fall top.

likewise: j h _ o fly bottom. (keeping respective horizontal positions).

here's have far, i'm inexperienced javascript/jquery , can't run.

vertical = new array(80); var textpos = 0; for(var = 0; < 80; ++i) {     vertical[i] = textpos;     textpos += 5; }  function poz(){     document.getelementsbyclassname("tops").style.top = '0px';     document.getelementsbyclassname("bottoms").style.bottom = '0px';     animate(); } function animate(){     for(var j = 0; j < 80; ++j) {         document.getelementsbyclassname("tops").style.top = vertical[j] + "px";         document.getelementsbyclassname("bottoms").style.bottom = vertical[j] + "px";     }  }  $('.uname').each(function(){     var letters = $(this).text().split('');     $(this).text('');     for(var = 0; < letters.length; i++){         if(i % 2 == 0){             $(this).append('<span class="tops">' + letters[i] + '</span>');         }         else{             $(this).append('<span class="bottoms">' + letters[i] + '</span>');         }     }     poz(); }); 

thanks in advanced!

p.s. if task can achieved css3, prefer option i'm not sure if it's possible.

//css

.bottoms{     margin-top:200px!important; } 

//script

  vertical = new array(80); var textpos = 0; for(var = 0; < 80; ++i) {     vertical[i] = textpos;     textpos += 5; }  function poz(){     // $(".tops").css('top','0px');    // $(".bottoms").css('bottom','0px');     //document.getelementsbyclasjqsname("bottoms").style.bottom = '0px';     animate(); } function animate(){      for(var j = 0; j < 80; ++j) {      //alert(vertical[j]);     //$(".tops").css('top',vertical[j]+'px');     //$(".bottoms").css('bottom',vertical[j]+'0');          if(vertical[j]<101){    $(".tops").animate({top:vertical[j]+'px'},500);    $(".bottoms").animate({bottom:vertical[j]+'px'},500);          $(".tops").css('position','relative');     $(".bottoms").css('position','relative');     $(".tops").css('float','left');     $(".bottoms").css('float','left');          }   //       document.getelementsbyclassname("tops").style.top = vertical[j] + "px";    //     document.getelementsbyclassname("bottoms").style.bottom = vertical[j] + "px";     }  }  $('.uname').each(function(){     var letters = $(this).text().split('');     $(this).text('');     for(var = 0; < letters.length; i++){         if(i % 2 == 0){             $(this).append('<span class="tops">' + letters[i] + '</span>');         }         else{             $(this).append('<span class="bottoms">' + letters[i] + '</span>');         }     }     poz(); }); 

//new fiddle link http://jsfiddle.net/pp44c/7/

now fine want . check it


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -