Created
July 16, 2018 18:19
-
-
Save walterjaworski/6285fc2bf9e30b69a5f4f2270847448d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function animate() { | |
var scrollTop = $(window).scrollTop(); | |
$('.animate').each(function(){ | |
var from = $(this).attr('data-from'); | |
var to = $(this).attr('data-to'); | |
var trigger = $(this).attr('data-trigger'); | |
if(isNumber(trigger)){ | |
var triggerNum = trigger; | |
}else{ | |
var triggerNum = $(trigger).offset().top; | |
} | |
console.log(trigger, from, to); | |
if(scrollTop >= triggerNum){ | |
$(this).removeClass(from).addClass(to); | |
}else{ | |
$(this).removeClass(to).addClass(from); | |
} | |
}); | |
$(window).scroll(function(){ | |
var scrollTop = $(window).scrollTop(); | |
$('.animate').each(function(){ | |
var from = $(this).attr('data-from'); | |
var to = $(this).attr('data-to'); | |
var trigger = $(this).attr('data-trigger'); | |
if(isNumber(trigger)){ | |
var triggerNum = trigger; | |
}else{ | |
var triggerNum = $(trigger).offset().top; | |
} | |
$('.teste').html(scrollTop +' - '+ triggerNum); | |
if(scrollTop >= triggerNum){ | |
$(this).removeClass(from).addClass(to); | |
//console.log('classe 1'); | |
}else{ | |
$(this).removeClass(to).addClass(from); | |
//console.log('classe 2'); | |
} | |
}); | |
}); | |
} | |
function isNumber(n) { | |
return !isNaN(parseFloat(n)) && isFinite(n); | |
} | |
animate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment