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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:11:01+00:00 2026-06-10T03:11:01+00:00

I have 2 div’s. One big yellow box and one small red box. I

  • 0

I have 2 div’s. One big yellow box and one small red box. I use jQuery to append the mousemove effect on the yellow box. When the mouse is over the yellow box, the mouseover causes the red box to follow the mouse. When then mouse reaches the red box “in” the yellow box, is no longer on mousemove on the yellow box and the red box stops follow the mouse. When the mouse enter the yellow box again it move with the mouse again – of course. The red box have to follow the mouse as long it is over the yellow box and not stop because it move over the red box itself. Is there a way to prevent that?

Thanks

Code here: http://jsfiddle.net/Illum/pPn3v/

<html>
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<style type="text/css">
#box1 {width: 500px; height: 500px; background-color: Yellow; border: 2px solid Blue;}
#box2 {width: 100px; height: 100px; background-color: red; border: 2px solid pink; z-index: 100; position: absolute;}    
</style>
</head>
<body>
<div id="box1"></div>
<div id="box2"></div>

<script type="text/javascript">
    $("#box1").bind('mousemove', function (e) {
        $("#box2").css("left", e.pageX);
        $("#box2").css("top", e.pageY);
    });
</script>

</body>
</html>
  • 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-10T03:11:01+00:00Added an answer on June 10, 2026 at 3:11 am

    I’ve written a solution to your problem here (jsfiddle). It may not be the cleanest solution, but it’s the only way I can think of accomplishing the task without embedding the div’s inside one another.

    I have basically added another listener to the “red” box that checks if it is still within the yellow box.

    var yellow = $('#yellow');
    var offset = yellow.offset();
    var offsetWidth = offset.left + yellow.width();
    var offsetHeight = offset.top + yellow.height();
    
    var red = $('#red');
    
    yellow.on('mousemove', function (e) {
        red.css("left", e.pageX);
        red.css("top", e.pageY);
    });
    
    red.on('mousemove', function (e) {
        if(e.pageX >= offset.left && e.pageY >= offset.top &&
           e.pageX <= offsetWidth && e.pageY <= offsetHeight) {
            red.css("left", e.pageX);
            red.css("top", e.pageY);  
        }               
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have several big images in my div, and one small magnifier image,
I have two divs, a big one and a smaller over the other, each
I have the below code on one page: <div id=prodoneid class=prodcls> <a href=javascript:void(changeIt('big.png', 'pagewrapid')());>
I have a big div with 3 small divs in it. You can look
Take a look at my page here: REMOVED I have a big red div
I have one big div with id=elements and I load from JSON file new
I have one parent DIV inside parent DIV i have two DIV one in
I have two div's one has textbox in it and other just plain text.
I have created a div there are two childs of that div one is
The scenario is I have two div s: one is where I select items

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.