Created
July 17, 2015 13:39
-
-
Save kirilkirkov/4883bce8f0762b85925d to your computer and use it in GitHub Desktop.
Simple div changing like Carousel. JS gets all divs with class game and rotate him. Compatibility Tested in jscc.info .
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> | |
<style> | |
.game {display:none;} | |
.active-g {display:block} | |
.checked {color:red;} | |
</style> | |
</head> | |
<body> | |
<div class="game game-1 active-g">Div 1</div> | |
<div class="game game-1 active-g">Div _1</div> | |
<div class="game game-2">Div 2</div> | |
<div class="game game-2">Div _2</div> | |
<div class="game game-3">Div 3</div> | |
<div class="game game-3">Div _3</div> | |
<a href="#game-1" class="change-g checked">X</a> | |
<a href="#game-2" class="change-g">X</a> | |
<a href="#game-3" class="change-g">X</a> | |
<script> | |
if ($('.game').length / 2 > 1) { | |
var current = 1; | |
var again = false; | |
function nextSlide() { | |
$('.game').fadeOut(1500); | |
$('.change-g').removeClass('checked'); | |
again == true ? again = false : current++; | |
$('.game-' + current).delay(1505).fadeIn(1500); | |
$("a[href='#game-" + current + "']").addClass('checked'); | |
if (current == $('.game').length / 2) { | |
again = true; | |
current = 1; | |
} | |
} | |
var interv = setInterval(function () { | |
nextSlide(); | |
}, 5000); | |
$('.change-g').click(function () { | |
clearInterval(interv); | |
$('.change-g').removeClass('checked'); | |
$(this).addClass('checked'); | |
var game = $(this).attr('href').replace('#', ''); | |
$('.game').hide(); | |
$('.' + game).show(); | |
}); | |
} | |
</script> | |
<!-- http://jscc.info/ - Compatibility Tested! --> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment