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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:29:26+00:00 2026-06-04T19:29:26+00:00

I have an animated div placed inside a div, I only want this div

  • 0

I have an animated div placed inside a div, I only want this div to be able to move in the space of it’s parent. How would I go about doing that?

Simply: I want frog contained within frogger.

HTML

<div id="frogger">                          <!-- Animate start -->
  <button id="left">&laquo;</button> <button id="right">&raquo;</button>
    <div id="frog">
    </div>
</div>                                      <!-- Animate end -->

CSS

#frogger
{
    width: 500px;
    height: 500px;
    border: solid;
    margin: 0 auto;
}

#frog
{
  position:relative;
  background-color:#abc;
  left:50px;
  width:90px;
  height:90px;
  margin:5px;
}

Javascript

$("#right").click(function(){
    if ($(':animated').length) {
        return false;
    } else {
        $("#frog").animate({"left": "+=50px"}, {queue: false}, "slow");
    }   
});

$("#left").click(function(){
    if ($(':animated').length) {
        return false;
    } else {
        $("#frog").animate({"left": "-=50px"}, {queue: false}, "slow");
    }
});
  • 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-04T19:29:28+00:00Added an answer on June 4, 2026 at 7:29 pm

    One way is to test the current position and not move if it is too close to the edge:

    var $frog = $("#frog");
    
    $("#right").click(function(){
        if (parseInt($frog.css('left')) >= 400 || $(':animated').length) {
            return false;
        } else {
            $frog.animate({"left": "+=50px"}, {queue: false}, "slow");
        }   
    });
    
    $("#left").click(function(){
    
        if (parseInt($frog.css('left')) < 50 || $(':animated').length) {
            return false;
        } else {
            $frog.animate({"left": "-=50px"}, {queue: false}, "slow");
        }
    });
    

    Demo: http://jsfiddle.net/n3NgY/

    Of course you can make this a bit more robust by determining the width of the frog and its container programmatically, but for the purpose of a quick demo I’ve just hardcoded the appropriate left and right boundary numbers.

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

Sidebar

Related Questions

I have an animated Brush object and i want to Clone this brush. ColorAnimation
I have the following setup: <div>Element with CSS3 animated height change</div> <div><a href=#>Link</a></div> I
I have <div class=animate> and in css: div.animate:hover{ //do stuff } But would also
I have an animated gif placed on the button. It's animating ok (most of
see this link...: Exemple on this site i have this code <body> <div id=geral>
I want to have a div that animates the currently active image out of
I have two divs, both with position:absolute; , one inside the other. The parent
I have a div called #footer , whose margin is animated using jQuery to
I have an animation for a div with two semi-transparent backgrounds: /* The animated
I'm trying to move a div by clicking a button and have an alert

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.