Skip to content

Instantly share code, notes, and snippets.

@meeDamian
Created November 29, 2011 09:38
Show Gist options
  • Save meeDamian/1404185 to your computer and use it in GitHub Desktop.
Save meeDamian/1404185 to your computer and use it in GitHub Desktop.
function main_rotator_init() {
zawsze najpierw wyczyść interwał a dopiero później ustawiaj nowy
clearInterval(interval);
interval = setInterval("main_rotator()",5000);
}
function main_rotator() {
// jakieś-tam zmiany w strukturze
$node = $('.current');
$node.hide();
$('.main').removeClass('current');
if($node.next().length) $node.next().addClass('current');
else $('.main:first').addClass('current');
$node = $('.selected');
$('.bullet').removeClass('selected');
if($node.next().length) $node.next().addClass('selected');
else $('.bullet:first').addClass('selected');
top.location.href = $('.selected a').attr('href');
}
function main_controller(interval) {
$('.bullet a').click(function(){
// najpierw wyczyść interwał
clearInterval(interval);
// pozmieniaj coś w strukturze
var clicked = $(this).attr('href');
top.location.href = clicked;
$('.main').removeClass('current');
$('.bullet').removeClass('selected');
$(this).parent().addClass('selected');
$(clicked).addClass('current');
// za 6 sekund ponownie wywołaj funkcję rotującą
setTimeout('main_rotator_init()',6000);
return false;
});
}
// globalny interwał działania funkcji
var interval;
$(function(){
// wywołanie funkcji rotującej
main_rotator_init();
// przypisanie zachowania na clicka
main_controller(interval);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment