Good morning, I am trying to implement animations to elements when they are shown on the screen, but I can not do it, I think the problem is in the JQuery code that I am using, since when trying to add a class to the object it does not, but if I execute anything else for example a alert
shows it, the code is as follows:
jQuery(document).ready(function ($) {
$('.darAnim').waypoint(
function(direction)
{
alert($(this).attr('id'));
$(this).toggleClass('main');
},
{offset: '70%',triggerOnce: true
});
});
This is the complete code
<style>.darAnim{/*opacity:0;*/}.main {font-size: 120%;color: red;</style>
<h1 id="n1" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="n2" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="n3" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="n4" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="n5" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="n6" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="n7" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="n8" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="n9" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="nn1" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="nn2" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="nn3" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="nn4" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="nn5" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="nn6" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<h1 id="nn7" class="darAnim" style="margin-bottom: 300px;">Example</h1>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type='text/javascript' src='https://github.com/imakewebthings/waypoints/blob/master/lib/jquery.waypoints.js'></script>
<script>
$(document).ready(function() {
$('.darAnim').waypoint(
function(direction) {
$(this).toggleClass('main');
}, {
offset: '70%',
triggerOnce: true
});
});
</script>