1

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
  • You need to check if the current "y coordinate" of the window is in the range of the "top y coordinate" of your element. Commented Mar 4, 2015 at 14:49

1 Answer 1

3

I am going to allow you to figure this one out. But here is the beginning code you need.

JSFiddle

$(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>

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.