I'm trying to use explode effect when element is scrolled to the view port. how can i make it explode only when its visible? I guess this is easy to accomplish, but I'm very new at jQuery and can't find the answer. Sorry if it was asked before
1 Answer
I am going to allow you to figure this one out. But here is the beginning code you need.
$(document).click(function () {
$("#toggle").toggle("explode");
});
$(document).scroll(function () {
var top = $(document).scrollTop();
if (top > 600) $("#toggle").toggle("explode");
if (top < 600) $('#two').hide();
});
#toggle {
width: 100px;
height: 100px;
background: #ccc;
position:fixed;
}
body {
height: 5000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<p>Click anywhere to toggle the box.</p>
<div id="toggle"></div>
1 Comment
Darius Serapinas
Thanks for your reply, Neoaptt. Actually I'm building a page with FullPage.js plugin installed ( alvarotrigo.com/fullPage/ ). So I guess I should pass in section ID to the if statement not distance from top?