In this article, we will create super cool timeline with cufon, animate.css and timelinr. you may see demos below:
Things we need:
In this article, we need to rewrite the jquery timelinr to add more effect and beautify it with cufon and anmimate.css, and we will use fixie.js to create all images we need.
HTML code:
- <div id="timeline">
- <ul id="dates">
- <li><a href="#2001">2001</a></li>
- <li><a href="#2002">2002</a></li>
- <li><a href="#2003">2003</a></li>
- <li><a href="#2004">2004</a></li>
- <li><a href="#2005">2005</a></li>
- <li><a href="#2006">2006</a></li>
- <li><a href="#2007">2007</a></li>
- </ul>
- <ul id="issues">
- <li id="2001">
- <img class="fixie" width="256" height="256" />
- <h1>2001</h1>
- <p class="fixie"></p>
- </li>
- <li id="2002">
- <img class="fixie" width="256" height="256" />
- <h1>2002</h1>
- <p class="fixie"></p>
- </li>
- <li id="2003">
- <img class="fixie" width="256" height="256" />
- <h1>2003</h1>
- <p class="fixie"></p>
- </li>
- <li id="2004">
- <img class="fixie" width="256" height="256" />
- <h1>2004</h1>
- <p class="fixie"></p>
- </li>
- <li id="2005">
- <img class="fixie" width="256" height="256" />
- <h1>2005</h1>
- <p class="fixie"></p>
- </li>
- <li id="2006">
- <img class="fixie" width="256" height="256" />
- <h1>2006</h1>
- <p class="fixie"></p>
- </li>
- <li id="2007">
- <img class="fixie" width="256" height="256" />
- <h1>2007</h1>
- <p class="fixie"></p>
- </li>
- </ul>
- <div id="grad_left"></div>
- <div id="grad_right"></div>
- <a href="#" id="next">+</a>
- <a href="#" id="prev">-</a>
- </div>
Modified timelinr plugin
- jQuery Timelinr GBin1.com
- tested with jQuery v1.7+
- Free under the MIT license.
- http:
- Fork from: http:
- ---------------------------------- */
- jQuery.fn.timelinr = function(options){
-
- settings = jQuery.extend({
- orientation: 'horizontal',
- containerDiv: '#timeline',
- datesDiv: '#dates',
- datesSelectedClass: 'selected',
- datesSpeed: 'normal',
- issuesDiv: '#issues',
- issuesSelectedClass: 'selected',
- issuesSpeed: 'fast',
- issuesTransparency: 0.2,
- issuesTransparencySpeed: 500,
- prevButton: '#prev',
- nextButton: '#next',
- arrowKeys: 'false',
- startAt: 1,
- autoPlay: 'false',
- autoPlayDirection: 'forward',
- autoPlayPause: 2000,
- cssAnimation: 'lightSpeedIn'
- }, options);
- $(function(){
-
- var howManyDates = $(settings.datesDiv+' li').length;
- var howManyIssues = $(settings.issuesDiv+' li').length;
- var currentDate = $(settings.datesDiv).find('a.'+settings.datesSelectedClass);
- var currentIssue = $(settings.issuesDiv).find('li.'+settings.issuesSelectedClass);
- var widthContainer = $(settings.containerDiv).width();
- var heightContainer = $(settings.containerDiv).height();
- var widthIssues = $(settings.issuesDiv).width();
- var heightIssues = $(settings.issuesDiv).height();
- var widthIssue = $(settings.issuesDiv+' li').width();
- var heightIssue = $(settings.issuesDiv+' li').height();
- var widthDates = $(settings.datesDiv).width();
- var heightDates = $(settings.datesDiv).height();
- var widthDate = $(settings.datesDiv+' li').width();
- var heightDate = $(settings.datesDiv+' li').height();
- var cssAnimation = settings.cssAnimation;
-
- if(settings.orientation == 'horizontal') {
- $(settings.issuesDiv).width(widthIssue*howManyIssues);
- $(settings.datesDiv).width(widthDate*howManyDates).css('marginLeft',widthContainer/2-widthDate/2);
- var defaultPositionDates = parseInt($(settings.datesDiv).css('marginLeft').substring(0,$(settings.datesDiv).css('marginLeft').indexOf('px')));
- } else if(settings.orientation == 'vertical') {
- $(settings.issuesDiv).height(heightIssue*howManyIssues);
- $(settings.datesDiv).height(heightDate*howManyDates).css('marginTop',heightContainer/2-heightDate/2);
- var defaultPositionDates = parseInt($(settings.datesDiv).css('marginTop').substring(0,$(settings.datesDiv).css('marginTop').indexOf('px')));
- }
- $(settings.datesDiv+' a').click(function(event){
- event.preventDefault();
-
- var whichIssue = $(this).text();
- var currentIndex = $(this).parent().prevAll().length;
-
- if(settings.orientation == 'horizontal') {
- $(settings.issuesDiv).animate({'marginLeft':-widthIssue*currentIndex},{queue:false, duration:settings.issuesSpeed});
- } else if(settings.orientation == 'vertical') {
- $(settings.issuesDiv).animate({'marginTop':-heightIssue*currentIndex},{queue:false, duration:settings.issuesSpeed});
- }
-
- $(settings.issuesDiv+' li').addClass('animated ' + cssAnimation).delay(1000).queue(function(next){
- $(this).removeClass('animated ' + cssAnimation);
- next();
- });
-
- $(settings.datesDiv+' a').removeClass(settings.datesSelectedClass);
- $(this).addClass(settings.datesSelectedClass).delay(500).queue(function(next){
- Cufon.refresh();
- next();
- });
- if(settings.orientation == 'horizontal') {
- $(settings.datesDiv).animate({'marginLeft':defaultPositionDates-(widthDate*currentIndex)},{queue:false, duration:'settings.datesSpeed'});
- } else if(settings.orientation == 'vertical') {
- $(settings.datesDiv).animate({'marginTop':defaultPositionDates-(heightDate*currentIndex)},{queue:false, duration:'settings.datesSpeed'});
- }
- });
- $(settings.nextButton).bind('click', function(event){
- event.preventDefault();
- if(settings.orientation == 'horizontal') {
- var currentPositionIssues = parseInt($(settings.issuesDiv).css('marginLeft').substring(0,$(settings.issuesDiv).css('marginLeft').indexOf('px')));
- var currentIssueIndex = currentPositionIssues/widthIssue;
- var currentPositionDates = parseInt($(settings.datesDiv).css('marginLeft').substring(0,$(settings.datesDiv).css('marginLeft').indexOf('px')));
- var currentIssueDate = currentPositionDates-widthDate;
- if(currentPositionIssues <= -(widthIssue*howManyIssues-(widthIssue))) {
- $(settings.issuesDiv).stop();
- $(settings.datesDiv+' li:last-child a').click();
- } else {
- if (!$(settings.issuesDiv).is(':animated')) {
- $(settings.issuesDiv).animate({'marginLeft':currentPositionIssues-widthIssue},{queue:false, duration:settings.issuesSpeed});
-
- $(settings.issuesDiv+' li').addClass('animated ' + cssAnimation).delay(1000).queue(function(next){
- $(this).removeClass('animated ' + cssAnimation);
- next();
- });
- $(settings.datesDiv).animate({'marginLeft':currentIssueDate},{queue:false, duration:'settings.datesSpeed'});
- $(settings.datesDiv+' a.'+settings.datesSelectedClass).removeClass(settings.datesSelectedClass).parent().next().children().addClass(settings.datesSelectedClass).delay(500).queue( function(next){
- next();
- Cufon.refresh();
- });
- }
- }
- } else if(settings.orientation == 'vertical') {
- var currentPositionIssues = parseInt($(settings.issuesDiv).css('marginTop').substring(0,$(settings.issuesDiv).css('marginTop').indexOf('px')));
- var currentIssueIndex = currentPositionIssues/heightIssue;
- var currentPositionDates = parseInt($(settings.datesDiv).css('marginTop').substring(0,$(settings.datesDiv).css('marginTop').indexOf('px')));
- var currentIssueDate = currentPositionDates-heightDate;
- if(currentPositionIssues <= -(heightIssue*howManyIssues-(heightIssue))) {
- $(settings.issuesDiv).stop();
- $(settings.datesDiv+' li:last-child a').click();
- } else {
- if (!$(settings.issuesDiv).is(':animated')) {
- $(settings.issuesDiv).animate({'marginTop':currentPositionIssues-heightIssue},{queue:false, duration:settings.issuesSpeed});
-
-
- $(settings.issuesDiv+' li').addClass('animated ' + cssAnimation).delay(1000).queue(function(next){
- $(this).removeClass('animated ' + cssAnimation);
- next();
- });
- $(settings.datesDiv).animate({'marginTop':currentIssueDate},{queue:false, duration:'settings.datesSpeed'});
- $(settings.datesDiv+' a.'+settings.datesSelectedClass).removeClass(settings.datesSelectedClass).parent().next().children().addClass(settings.datesSelectedClass).delay(500).queue(
- function(next){
- next();
- Cufon.refresh();
- });
- }
- }
- }
- });
- $(settings.prevButton).click(function(event){
- event.preventDefault();
- if(settings.orientation == 'horizontal') {
- var currentPositionIssues = parseInt($(settings.issuesDiv).css('marginLeft').substring(0,$(settings.issuesDiv).css('marginLeft').indexOf('px')));
- var currentIssueIndex = currentPositionIssues/widthIssue;
- var currentPositionDates = parseInt($(settings.datesDiv).css('marginLeft').substring(0,$(settings.datesDiv).css('marginLeft').indexOf('px')));
- var currentIssueDate = currentPositionDates+widthDate;
- if(currentPositionIssues >= 0) {
- $(settings.issuesDiv).stop();
- $(settings.datesDiv+' li:first-child a').click();
- } else {
- if (!$(settings.issuesDiv).is(':animated')) {
- $(settings.issuesDiv).animate({'marginLeft':currentPositionIssues+widthIssue},{queue:false, duration:settings.issuesSpeed});
- $(settings.issuesDiv+' li').addClass('animated ' + cssAnimation).delay(1000).queue(function(next){
- $(this).removeClass('animated ' + cssAnimation);
- next();
- });
-
-
- $(settings.datesDiv).animate({'marginLeft':currentIssueDate},{queue:false, duration:'settings.datesSpeed'});
- $(settings.datesDiv+' a.'+settings.datesSelectedClass).removeClass(settings.datesSelectedClass).parent().prev().children().addClass(settings.datesSelectedClass).delay(500).queue( function(next){
- next();
- Cufon.refresh();
- });
- }
- }
- } else if(settings.orientation == 'vertical') {
- var currentPositionIssues = parseInt($(settings.issuesDiv).css('marginTop').substring(0,$(settings.issuesDiv).css('marginTop').indexOf('px')));
- var currentIssueIndex = currentPositionIssues/heightIssue;
- var currentPositionDates = parseInt($(settings.datesDiv).css('marginTop').substring(0,$(settings.datesDiv).css('marginTop').indexOf('px')));
- var currentIssueDate = currentPositionDates+heightDate;
- if(currentPositionIssues >= 0) {
- $(settings.issuesDiv).stop();
- $(settings.datesDiv+' li:first-child a').click();
- } else {
- if (!$(settings.issuesDiv).is(':animated')) {
- $(settings.issuesDiv).animate({'marginTop':currentPositionIssues+heightIssue},{queue:false, duration:settings.issuesSpeed});
- $(settings.issuesDiv+' li').addClass('animated ' + cssAnimation).delay(1000).queue(function(next){
- $(this).removeClass('animated ' + cssAnimation);
- next();
- });
-
-
- $(settings.datesDiv).animate({'marginTop':currentIssueDate},{queue:false, duration:'settings.datesSpeed'},{queue:false, duration:settings.issuesSpeed});
- $(settings.datesDiv+' a.'+settings.datesSelectedClass).removeClass(settings.datesSelectedClass).parent().prev().children().addClass(settings.datesSelectedClass).delay(500).queue(
- function(next){
- next();
- Cufon.refresh();
- });
- }
- }
- }
- });
-
- if(settings.arrowKeys=='true') {
- if(settings.orientation=='horizontal') {
- $(document).keydown(function(event){
- if (event.keyCode == 39) {
- $(settings.nextButton).click();
- }
- if (event.keyCode == 37) {
- $(settings.prevButton).click();
- }
- });
- } else if(settings.orientation=='vertical') {
- $(document).keydown(function(event){
- if (event.keyCode == 40) {
- $(settings.nextButton).click();
- }
- if (event.keyCode == 38) {
- $(settings.prevButton).click();
- }
- });
- }
- }
-
- $(settings.datesDiv+' li').eq(settings.startAt-1).find('a').trigger('click');
-
- if(settings.autoPlay == 'true') {
- setInterval("autoPlay()", settings.autoPlayPause);
- }
- });
- };
-
- function autoPlay(){
- var currentDate = $(settings.datesDiv).find('a.'+settings.datesSelectedClass);
- if(settings.autoPlayDirection == 'forward') {
- if(currentDate.parent().is('li:last-child')) {
- $(settings.datesDiv+' li:first-child').find('a').trigger('click');
- } else {
- currentDate.parent().next().find('a').trigger('click');
- }
- } else if(settings.autoPlayDirection == 'backward') {
- if(currentDate.parent().is('li:first-child')) {
- $(settings.datesDiv+' li:last-child').find('a').trigger('click');
- } else {
- currentDate.parent().prev().find('a').trigger('click');
- }
- }
- }
javascript we used in these demo
- $(function(){
- Cufon.replace('#timeline a, #timeline h1').CSS.ready(function() {
- $().timelinr({autoPlay:'true', autoPlayPause:'3000', cssAnimation:'tada'});
- });
- });
Hope you will like it. thanks!