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 7717011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:46:34+00:00 2026-06-01T02:46:34+00:00

What I wanna achieve is animate a div up and down until next click

  • 0

What I wanna achieve is animate a div up and down until next click when it should stop and wait for another click to start animating again.

http://jsfiddle.net/WwJRD/

this is the function animating my div:

function upAndDown(element,x) {

    $(element).animate({'top':'+='+x+'px'}, 'slow')
    .animate({'top':'-='+x+'px'}, 'slow',function(){upAndDown(element,x)});
};

$('.clickThis').click(function(){
    upAndDown('.moveThis',50);
});

I really dont know how to get what I want!

Thanks

  • 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-01T02:46:36+00:00Added an answer on June 1, 2026 at 2:46 am

    This is actually a little tricky, because you have multiple queued animations and a callback.

    The problem is if you just stop, and then call upAndDown later, you will start animating from the current position, meaning you might move around the page sporadically. You can’t jumpToEnd in the stop() call either, because you will still call the callback.

    I fixed this by adding a class moving when (appropriately) the object is moving. This is used in the callback to decide whether to keep animating.

    You end up with this:

    http://jsfiddle.net/EkpNK/

    Now, this keeps animating until it finishes a cycle. If you want to have it stop immediately, you can call .stop(false, true) twice to stop both animations and return to the original spot:

    http://jsfiddle.net/EkpNK/1/

    If you want to stop in place and continue from where you left off, it will take some extra code.

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

Sidebar

Related Questions

I wanna to achieve an effect like a fired blue ball (ball with energy)
That's what I wanna achieve : There will be dll which contains only methods
I have an app in android in which I wanna achieve the following thing:
I wanna to achieve a Fog effect using AndEngine for Android. Just some moving
Wanna write a RegEx to validate a driving license. if it doesn't start with
When I click a button, I wanna do some things listed below using HTML5
I wanna grid in jqGrid should vary its size dynamically depending on the window
Greetings everyone, i just wanna ask.. how do i disable the right click property
i wanna add a service behavior(or anything u'll suggest) that will automatically insert the
I wanna verify a digitally signed xml against its schema definition while this schema

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.