Last active
December 19, 2015 15:09
-
-
Save j8/5974214 to your computer and use it in GitHub Desktop.
Auto rotation slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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