Developing interactive components for websites usually require the same code like equal div Height, Browser detection, preloading images, disabling right-click.. etc.

Yeah you guessed it right, today we gonna share some life saving jQuery snippets that will help you do simple tasks.
$(window).load(function() {
// Animate loader off screen
$("#loader").animate({
top: -200
}, 1500);
});
// where loader is <img src="download.png" id="loader">
//and first element to be loaded.
$('#foo').bind('click', function() {
alert('User clicked on "foo."');
});
$(document).ready(function() {
$("myLink").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {
duration: 450,
easing: "easeOutBounce"
});
return false;
});
});
$('link[media='screen']').attr('href', 'Alternative.css');
$.expr[':']['nth-of-type'] = function(elem, i, match) {
var parts = match[3].split("+");
return (i + 1 - (parts[1] || 0)) % parseInt(parts[0], 10) === 0;
};
$(document).ready(function(){
$("ul > li").click(function () {
var index = $(this).prevAll().length;
});
});
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
$(document).ready(function(){
$(imageobj).attr('src', $(imageobj)
.attr('src') + '?' + Math.random() );
});
$(document).ready(function(){
$('a[href]').each(function() {
if((C = $(this).attr('href').match(/[.](doc|xls|pdf)$/))) {
$(this).addClass(C[1]);
}
});
});
// images that a browser can't find fire off an "error" JavaScript event we can watch for.
$('img').error(function(){
$(this).attr('src', 'missing.png');
});
// Or, hide them
$("img").error(function(){
$(this).hide();
});
Hope this helps.
This entry was posted on Monday, January 2nd, 2012 at 4:20 pm
and is filed under
Tutorials .
You can follow any responses to this entry through the
RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Good stuff… but..
03 has no smooth scroll – another header but repeat of 02 code snippet.
09 and 10 are the same as well – both in header and in code snippet.
Yeah my bad, fixed the duplication and missing snippet.