[jQuery]setInterval

by tea4two

HTML

<p><span>loading...</span></p>

<a href="#" id="btn">STOP</a>

CSS

p {
    margin-bottom: 50px;
    color: #555;
    font-size: 160%;
    font-weight: bold;
}

JavaScript

var _timer;

_timer = setInterval(function () {
            $('p').find('span').fadeTo(200,.4).fadeTo(200,1);
            console.log('loading...');
        }, 100);


var clearTimer = function() {
    clearInterval(_timer);
    
    $('#btn').remove();
    $('p').fadeOut('fast');
    
    return false;
};

$('#btn').on('click', function() {
    clearTimer();
});