jQuery beatiful code examples
I really like the semantics of jQuery, is fairly short and predictable.
Look at the code, it is not overloaded with ambiguous and unclear structures.
Like Ruby, the methods often returns a jQuery object, so you can create a chain of methods.
I want to share the code that I wrote last night. If you are not familiar jQuery, so look over the code.
...
$("#pics_hide").click(function(){
$("#images div:first-child").animate({opacity: "0.1"}, 300,
function(){$(this).next().animate({opacity: "0.1"},
arguments.callee);
return false
}
);
});
$("#pics_show").click(function(){
$("#images div:last-child").animate({opacity: "1.0"}, 300,
function(){$(this).prev().animate({opacity:"1.0"},
arguments.callee);
return false
}
);
});
$("#pics_move").hover(
function(){
$("#images div:even").hide("slow")
},
function(){
$("#images div:even").show("slow")
});
$("#pics_reorder").click(function(){
$("#images div:last-child")
.insertBefore($("#images div:first-child"));
$("#images div:even").animate({opacity: "0.4"}, 300);
$("#images div:odd").animate({opacity: "1.0"}, 300);
});
$("#pics_anim").click(function(){
$("#images div:odd").animate({top: '-=20px'}, 300);
$("#images div:even").animate({top: '+=20px'}, 300);
});
...
2 comments
Comments
-
I really like jquery a lot as well and I have been wondering for some time to learn ruby. Is is possible and easy to mix ruby/rails and jquery?
best regards
-
Sure, it's possible. Easiest way to do it is 'jRails' = jQuery on Rails.