Skip to content

Instantly share code, notes, and snippets.

@temberature
Created May 28, 2018 03:41
Show Gist options
  • Save temberature/0d4be9e214201b788d5017799b2ecc85 to your computer and use it in GitHub Desktop.
Save temberature/0d4be9e214201b788d5017799b2ecc85 to your computer and use it in GitHub Desktop.
var bulletinBoard = {
OPTIONS: {
$wrap: '',
interval: 3000,
switchTime: 1000
},
cache: {},
init: function(options) {
var me = this,
ca = me.cache;
$.extend(me.OPTIONS, options);
ca.$bulletins = me.OPTIONS.$wrap.find('.bulletin');
var $active = ca.$bulletins.eq(0).addClass('active');
ca.length = ca.$bulletins.length;
ca.active = 0;
$active.css({
top: 0
});
ca.$active = $active;
setInterval(function() {
me.switch();
}, me.OPTIONS.interval);
},
switch: function() {
var me = this,
ca = me.cache;
ca.$active.animate({
top: '-100%'
}, me.OPTIONS.switchTime)
.removeClass('active');
ca.active = (ca.active + 1) % ca.length;
var $to = ca.$bulletins.eq(ca.active);
ca.$active = $to.css({
top: '100%'
})
.animate({
top: 0
}, me.OPTIONS.switchTime)
.addClass('active');
}
};
bulletinBoard.init({
$wrap: ca.$bulletinBoard
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment