Skip to content

Instantly share code, notes, and snippets.

@j8
Last active December 19, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j8/5974214 to your computer and use it in GitHub Desktop.
Save j8/5974214 to your computer and use it in GitHub Desktop.
Auto rotation slider
// Front page slider
$(document).ready(function() {
$('ul#frontpageslider li a').click(function(e) {
var headingAppending = $(this).children('.headingToMove').text();
var textAppending = $(this).children('.firstCharsToMove').html();
var imageAppending = $(this).children('.newsImageToMove').html();
var linkAppending = $(this).children('.linkToMove').text();
$("#titleAppender").empty();
$("#titleAppender").append(headingAppending);
$("#textAppender").empty();
$("#textAppender").append(textAppending);
$('#linkAppender').attr("href", '');
$('#linkAppender').attr("href", linkAppending);
if (imageAppending == '') {
return;
} else {
$("#imageAppender").attr("src", imageAppending);
}
clearInterval(timer);
// Toggle active class
$('ul#frontpageslider li').removeClass("active");
$(this).parent().addClass("active");
var parent = $(this).parent();
var index = $(this).index(parent);
timer=setInterval(go, 2000);
return false;
});
$('ul#frontpageslider li:first a').click();
var timer=setInterval(go, 2000);
function go() {
var $next = $('ul#frontpageslider li.active').next();
if ($next.length == 0){
console.log("no next");
$next = $('ul#frontpageslider li:first');
}
$next.children('a').click();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment