Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-27-2011, 03:01 AM   PM User | #1
bcapp
New Coder

 
Join Date: Nov 2010
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
bcapp is an unknown quantity at this point
JQuery Follow Mouse Problem

I am using this code to make a div follow the mouse.

[CODE]
var mouseX = 0, mouseY = 0;
$(document).mousemove(function(e){
mouseX = e.pageX;
mouseY = e.pageY;
});

// cache the selector
var follower = $("#follower");
var xp = 0, yp = 0;
var loop = setInterval(function(){
// change 12 to alter damping, higher is slower
xp += (mouseX - xp) / 12;
yp += (mouseY - yp) / 12;
follower.css({left:xp, top:yp});

}, 30)
[ICODE]

Is there a way to make the div not move when the mouse is within its parameters? I am using an image in the div and I want the div to follow the mouse when it moves with a lag as it already does but when the mouse is over the div or within its parameters i want it to stay put. In other words, I would like to "deactiviate" the follow mouse property when the cursor is in the div and then have it "reactivated " once the mouse leaves the div or moves away from it (when you roll over the div, a menu animates and slides out to the left. If the div continues to follow the mouse even when the mouse is on top of it then you can never click on any of the menu items). Any comments would be appreciated. Thanks.
bcapp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:59 AM.


Advertisement
Log in to turn off these ads.