Jump to content

Recommended Posts

ofcourse there is,however, it is a little tricky.. you see, mouse position is not very cross-browser (interms of the properties you're using from the MouseEvent object), therefore its probably a good idea to use a cross-browser solution (jQuery

 

however, if you do NOT want to use a cross-browser solution you will need to calculate and manipulate the data you receive from the event

 

in IE6-8 'x' and 'y' will represent the cursor position INSIDE the firing element, where as.. Chrome and Firefox will use layerX and layerY to do/represent this..

 

you will also need to know the width of the content within the overflowing div.. its usually a good idea to structure this like this:

<div id="container" style="overflow: hidden; width: 500px; height: 100px;">
  <div id="content">
    <!-- enter all your content here!  -->
  </div>
</div>

 

 

this way you can use the element #content to get the width of the entire content.. ALSO you can just slide this div left and right using css :) OR you can use the .scrollLeft() method of #container

 

Whichever is clever :)

 

last thing you'll need to do is calculate your mouse's position within an element against your content div's width..

 

for example.. you will want to use this formula..

 

(MouseX / ContainerWidth) * ContentWidth

 

and that will give you the amount to move the #content element from the right..

 

using this javascript line:

document.getElementById('#content').style.right = (MouseX / ContainerWidth) * ContentWidth;

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.