I created a code to add a class to a div, but it's not working as expected. I need help troubleshooting this issue. The code works fine on codePen, but not on my WordPress website. How can I make sure the browser executes this code properly?
Link to the file I'm working on:
The desired functionality is for the second div to fade in when it enters the view-port.
UPDATED CODE:
jQ
<script>
function isScrolledIntoView(elem) {
var docViewTop = jQuery(window).scrollTop();
var docViewBottom = docViewTop + jQuery(window).height();
var elemTop = jQuery(elem).offset().top;
var elemBottom = elemTop + jQuery(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
jQuery(window).scroll(function () {
jQuery('.anim').each(function () {
if (isScrolledIntoView(this)) {
jQuery(this).addClass('anima').removeClass('viss')
}
});
});
</script>
CSS
.anima span{
display: inline-block;
transition: 3s;
opacity: 0;
animation-duration: 1s;
animation-name: fInUpSmall;
animation-fill-mode: forwards;
}
@keyframes fInUpSmall{
0%{
opacity:0;
transform:translateY(15px)}
100%{
opacity:1;
transform:translateY(0)}
}
.anima span:nth-child(1) {
animation-delay: .1s;
}
.anima span:nth-child(2) {
animation-delay: .25s;
}.anima span:nth-child(3) {
animation-delay: .4s;
}.anima span:nth-child(4) {
animation-delay: .55s;
}.anima span:nth-child(5) {
animation-delay: .7s;
}.anima span:nth-child(6) {
animation-delay: .85s;
}
.anima span:nth-child(7) {
animation-delay: 1s;
}
.anima span:nth-child(8) {
animation-delay: 1.15s;
}
.anima span:nth-child(9) {
animation-delay: 1.3s;
}
.viss{
visibility: hidden;
}
HTML
<div class="anim">
<span>Set</span> <span>a</span> <span>path</span> <span>and</span> <span>get</span> <br><span class="highlight">to </span><span class="highlight">your </span><span class="highlight">destination </span></div>