I would like to activate this box animation once the user scrolls down by adding a class.
I'm having trouble getting this to work, it seems like I might be missing something crucial. Here is my current code, can someone point out where I am going wrong? Thank you!
HTML
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="600px" height="600px" viewBox="0 0 600 600" enable-background="new 0 0 600 600" xml:space="preserve">
<rect class="box" x="147.297" y="237.162" fill="#FFFFFF" stroke="#000000" stroke-width="8" stroke-miterlimit="10" width="305.405" height="125.676"/>
</svg>
CSS
@keyframes offset{
100%{
stroke-dashoffset:0;
}
}
.box{
stroke:transparent;
}
.box.draw{
stroke:#202020;
stroke-width:5;
stroke-dasharray:910;
stroke-dashoffset:910;
animation: offset 5s linear forwards;
}
jQuery/JS
$(function() {
var boxDraw = $(".box");
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 400) {
box.addClass("draw");
}
});
});
Furthermore, is there a way to trigger an animation after reaching a specific point on the page rather than using a scroll value? Any assistance would be greatly appreciated.