Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:50:18+00:00 2026-06-10T10:50:18+00:00

I am using jQuery animate to change the position of multiple elements on the

  • 0

I am using jQuery animate to change the position of multiple elements on the page (decorative elements). I want the element to be deleted if it exits body area. (if left is larger than body width or top is larger than body height).

The following can not be used in my case:

  • overflow hidden for the body
  • manually animating the element. I want to use jQuery animate to keep it simple (I dinamically create elements, animate them then I don’t care about them, don’t keep track of them, they have a .remove() methode when the animation is complete)

http://jsfiddle.net/a7Nck/

So in this JSfiddle I want the red div to dissappear when it reaches right edge of the body so that no scrollbars will appear.

Isn’t there any CSS3 media query for example so that if a div is not in the viewport it will be hidden?

EDIT:

I just thought of a solution: get the width of the body prior to triggering the animation and then animate the top and left by using the minimum between the body size and what the animation should do. The problem is that this will affect animation speed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:50:20+00:00Added an answer on June 10, 2026 at 10:50 am

    You can use animate’s step function.

    The second version of .animate() provides a step option — a callback function that is fired at each step of the animation. This function is useful for enabling custom animation types or altering the animation as it is occurring. It accepts two arguments (now and fx), and this is set to the DOM element being animated.

    var w = $(window).width()
    $('div').animate({
        left: '20px'
    }, 500).delay(1000).animate({
        left: '2000px'
    }, {
        step: function(now, fx) {
            if (now > w) {
                $(fx.elem).remove()
            }
        }
    }, 1000);
    

    Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use .animate to change colors when .bind('click') is fired, using jquery
I am using jQuery Transit to animate a changing element. I am animating multiple
I’m using jQuery to animate DOM element on the page and I hit an
I have a few divs that I want to animate using jQuery. However, I
I'm using jquery to change/animate bg positions of a menu item, but I need
while loading a page i am using a animation, wid=jQuery(window).width()+400; jQuery('#div').animate({'marginLeft' : '+='+wid+'px'},{queue:false, duration:20000
I'm using jQuery to animate a height change on hover(). Upon hover, it'll apply
I have an iframe tag and I want to dynamically change it using jquery
I'm using the animate() function to change the background position of a button on
I am using jquery animate to change the size of a div when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.