Lightest jquery content slider ever – 380 bytes
In CSS, HTML, jquery, by Steve
Today evening i was wondering that why jquery plugins made very complex and why are not lightweight. Jquery has a inbuilt function “animate()” which really create tremendous effects.
Therefore i made one content slider using this animate function and found that its script excluding “jquery.js” is less than 380 bytes , yes i repeat its 380 bytes. Sounds cool and great.
Just check out DEMO here.
Copy and Paste the HTML inside body tag of your html:
.
Copy and paste CSS inside style tag of your html page:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#myslide {width:160px;overflow:hidden;position: relative;height:170px;margin-bottom:20px} #myslide .cover{ width:480px; /*------- class mystuff width * number of mystuff divs (160 * 3 = 480)---------- */ position: absolute; height:160px; } #myslide .mystuff {width:160px;float:left;padding:20px 0;} .button1,.button2,.button3{background:#999;padding:6px;display:block;float:left;margin-right:5px;} .active{background:#111;padding:6px;display:block;float:left;outline:none;} .clear{clear:both;} |
.
And here is the master jquery code (389 bytes), copy and paste under head tag of your html:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$(document).ready(function (){ $('#button a').click(function(){ var integer = $(this).attr('rel'); $('#myslide .cover').animate({left:-160*(parseInt(integer)-1)}) /*----- Width of div mystuff (here 160) ------ */ $('#button a').each(function(){ $(this).removeClass('active'); if($(this).hasClass('button'+integer)){ $(this).addClass('active')} }); }); }); |
.
Thats all folks. Check out working DEMO.
Cheers!