Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cythilya committed Dec 27, 2015
1 parent 3f21514 commit c511445
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions js/jquery.newsticker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@
$next,
stop = false;

$newsticker.init = function(){
function init(){
$item.eq(0).addClass('current'); //set start item
$newsticker.suspend();

if($.isFunction(config.move)){
config.move.call(this);
}
else{
$newsticker.move();
}
suspend();
move();
};

$newsticker.suspend = function(){
function suspend(){
$newsticker.on('mouseover mouseout', function(e) {
if (e.type == 'mouseover') {
stop = true;
Expand All @@ -38,26 +32,31 @@
});
};

$newsticker.move = function(){
setInterval(function() {
if (!stop) {
var $current = $frame.find('.current');
function move(){
if($.isFunction(config.move)){
config.move.call(this);
}
else{
setInterval(function() {
if (!stop) {
var $current = $frame.find('.current');

$frame.animate({
top: '-=' + config.height + 'px'
}, config.speed, function() {
$next = $frame.find('.current').next();
$next.addClass('current');
$current.removeClass('current');
$current.clone().appendTo($frame);
$current.remove();
$frame.css('top', config.start + 'px');
});
}
}, config.interval);
$frame.animate({
top: '-=' + config.height + 'px'
}, config.speed, function() {
$next = $frame.find('.current').next();
$next.addClass('current');
$current.removeClass('current');
$current.clone().appendTo($frame);
$current.remove();
$frame.css('top', config.start + 'px');
});
}
}, config.interval);
}
};

$newsticker.init();
init();
}
// initialize every element
this.each(function() {
Expand Down

0 comments on commit c511445

Please sign in to comment.