sábado, 2 de marzo de 2013

Tekpub & javascript

I've watched the video about javascript by tekpub guys, while I've coded I've listened mix seven lions. This the plain javascript code result. It's a nice exercise for improving the javascript skills.
The Code:
var cycler = function(parentContainer){
 var listContainer = $(parentContainer);
 var firstPost = $(parentContainer + " li:first");
  
 cycle  = function(){
  removeFirst();
 }

 removeFirst = function(){
  firstPost.fadeOut(appendToEnd);
 };

 appendToEnd = function(post){
  firstPost.remove();
  listContainer.append(firstPost);
  firstPost.fadeIn(); 
 };


 return{
  cycle : cycle
 }
};

$(function(){
 $("#btnCycler").click(function(){
  var listCycler = new cycler("#posts");
  listCycler.cycle();
 });
});

The HTML:

JS Demo

  • First text
  • Second text
  • Thrid
  • Fourth Text

No hay comentarios:

Publicar un comentario