Move a div with mouse position
Hi,
Here is my testpage's url :
http://www.itch.fr/test/
I wrote this little code in order to move a div into another one, with mouse position. But my code works only when mouse is moving, as I want it to make the move continue when the mouse is to the left or to the right of the middle of the user's window.
Here is the code :
- $(document).ready(function(){
- //Taille du div container
- divwidth = $("#book_container").width();
- milieu = divwidth/2;
- positionX=0;
- pixels=0;
- css=0;
-
- $().mousemove(function(f){
- positionX = f.pageX;
-
- if (positionX<milieu){
- difference = milieu - positionX;
- ratio = difference/milieu;
- pixels = ratio*10;
- } else {
- difference = positionX - milieu;
- ratio = difference/milieu;
- pixels = -ratio*10;
- }
-
- $('#ma-zone').html("positionX : "+positionX+"<br>milieu : "+milieu+"<br>difference : "+difference+"<br>ratio : "+ratio+"<br>pixels : "+pixels+"<BR>css : "+css+"<BR>");
- css=parseInt($('#book_elements').css('left'));
- pixels=css*1+pixels*1;
- $("#book_elements").css("left",pixels);
- });
- });
Thx for your help...