Add and remove class in loop using jquery
setInterval(function(){
$('#topcontrol img').toggleClass('wiggle');
setTimeout(function(){
$('#topcontrol img').toggleClass('wiggle');
},500);
},1000);
Add class one by one using jquery
$("ul li").on('click' , function () {
setInterval(function(){
var el = $('.main_div');
var index = 0;
var timer = window.setInterval(function(){
if (index < el.length) {
el.eq(index++).addClass('highlighted');
} else {
window.clearInterval(timer);
}
}, 1000);
}, 1);
});
Add class on scroll using jquery
function isScrolledIntoView(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top + 100;
var elemBottom = elemTop + $(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
$(window).on('scroll', function() {
$("div").each(function() {
if (isScrolledIntoView($(this))) {
$(this).addClass("classname");
}
});
});