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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:42:56+00:00 2026-05-26T10:42:56+00:00

I am having trouble working out how to create a simple pop-and-drop effect for

  • 0

I am having trouble working out how to create a simple pop-and-drop effect for a class of divs. Since the onmouseover events of each of the items in this class are currently calling the same function, rapidly mousing between divs leaves the previous div stuck halfway through (if you mouse on and off from the bottom of the div, you’ll see the effect I’m trying to produce).

My current approach also calls for me to replicate quite a bit of code to call the function from each individual div’s event handlers, so if there’s a way to wrap those up into one function I’d really like to know how. I’m sure there’s a simple and efficient way to do all this, just can’t seem to work it out.

jsFiddle example: http://jsfiddle.net/DvXDb/

Here’s my code (script at the bottom):


div.bouncer{
       position:relative;
        top:50px;
    }




    function next(elem) {
        do {
            elem = elem.nextSibling;
        } while (elem && elem.nodeType != 1);
        return elem;
    }
    var thisDiv; var nextDiv; var selDiv;
    var containerDivList = document.getElementsByClassName("container");
    var containerArray = Array.prototype.slice.call(containerDivList);
    var container1 = containerArray[0];
    var container2 = containerArray[1];
    var container3 = containerArray[2];
    var container4 = containerArray[3];
    container1.onmouseover = function () {
        callPop(this.getElementsByTagName('div')[0]);
    }
    container1.onmouseout = function () {
        callDrop(this.getElementsByTagName('div')[0]);
    }
    container2.onmouseover = function () {
        callPop(this.getElementsByTagName('div')[0]);
    }
    container2.onmouseout = function () {
        callDrop(this.getElementsByTagName('div')[0]);
    }
    container3.onmouseover = function () {
        callPop(this.getElementsByTagName('div')[0]);
    }
    container3.onmouseout = function () {
        callDrop(this.getElementsByTagName('div')[0]);
    }


    var relativeHeights = ['0px', '5px', '10px', '15px', '20px', '25px', '30px', '35px', '40px', '45px', '50px'];
    var index = 10;
    var intervalHandle1;
    function callPop(thisDiv) {
        clearInterval(intervalHandle1);
        selDiv = thisDiv;
        intervalHandle1 = setInterval(popImage, 5);
    }
    function callDrop(thisDiv) {
        clearInterval(intervalHandle1);
        selDiv = thisDiv;
        intervalHandle1 = setInterval(dropImage, 5);
    }
    function popImage() {
        selDiv.style.top = relativeHeights[index];
        index--;
        if (selDiv.style.top === '0px') {
            index = 0;
        }
    }
    function dropImage() {
        index++;
        selDiv.style.top = relativeHeights[index];
        if (selDiv.style.top === '50px') {
            index = 10;
        }
    }
  • 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-05-26T10:42:57+00:00Added an answer on May 26, 2026 at 10:42 am

    Here’s an example using jQuery, you really should be using a Framework for things like this. They simplify everything.

    http://jsfiddle.net/AEJY9/

    $(function () {
    
    $('.bouncer').hover(
      function () {
        $(this).stop().animate({
          top: 10
          }, 500);
      },
      function () {
        $(this).stop().animate({
          top: 50
          }, 500);
      }
    );
    
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble working out how to get a simple fade in fade
I'm working on a simple 2D game engine in Java, and having no trouble
I'm having a little trouble working out how to display a running total of
Ok so I'm working on my homework and am having trouble figuring out how
Having trouble working out why my xml updates are failing on IsolatedStorage and was
I'm having trouble working out how to insert multiple-depths of nested schema in MongoDB,
I'm working on my first Core Data-backed app and am having trouble figuring out
I'm having trouble working out a query. I've tried subqueries, different joins and group_concat()
I'm having trouble with getting a named scope working using using an attribute of
I am having trouble with a homework question that I've been working at for

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.