Results 1 to 6 of 6

Thread: javascript on mouse move

  1. #1
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript on mouse move

    hi guys,

    i need some help adding some javascript on my html. below is my html code.

    HTML Code:
    <html>
    <title>Javascript Help</title>
    </head>
    
    <body style="background-color: #FFCC00; ">
    
    <div id="graybox" style="width: 800px; height: 350px; margin: 100px auto; background-color: #CCCCCC;">
    
    	<div id="pointer" style="width: 10px; height: 50px; background-color:#0099FF; position: absolute; top: -1; left: 50%; "></div>
    
    </div>
    
    
    </body>
    </html>

    i want the pointer (blue rectangle) to follow my mouse position whenever i enter the graybox, the pointer should move only left and right.

    thanks!

  2. #2
    Join Date
    Dec 2006
    Posts
    47
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default

    This is from a drag script I modify for different purposes, there is a cross browser script too but, this should suffice for IE

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <
    HEAD>
    <
    TITLE>__</TITLE>
    <
    STYLE type=text/CSS>

    </
    STYLE>

    </
    HEAD>
    <
    body style="background-color: #FFCC00; ">

    <
    div id="graybox" style="width: 800px; height: 350px; margin: 100px auto; background-color: #CCCCCC;">

        <
    div  id="pointer" style="width: 10px; height: 50px; background-color:#0099FF; position:relative "></div>

    </
    div>
    <
    SCRIPT type="text/javascript">
     var 
    moveapproved=false;     var z,x,y,w;
    function 
    move(){ 
        if(
    moveapproved){z.style.pixelLeft=event.clientX-10;    return false;}
    }
    function 
    moves(){
       
    moveapproved=truez=document.getElementById('pointer');w=document.getElementById('graybox')
       
    x=event.clientX;y=event.clientY;document.onmousemove=move;
    }
    document.getElementById('graybox').onmouseover=moves;
    document.getElementById('graybox').onmouseout=new Function("moveapproved=false");

    </SCRIPT>

    </BODY></HTML> 

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Kenny, that only works in IE... If you go to this page:
    http://www.dynamicdrive.com/dynamici...drag/index.htm
    And you scroll somewhat to the bottom, you'll see scrollers that only go left and right, and some that only go up and down. I'm sure you can find a way of putting these into your box, if you can't just tell me and I can do it for you.
    I hope this helps,
    Nile
    Jeremy | jfein.net

  4. #4
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Not even in IE7, for me. It is really messed up. I tried it. I'm not taking it to use, I just came here to see what Nile was saying. Just testing...

    -magicyte
    Last edited by magicyte; 11-03-2008 at 03:40 AM.

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Magicye, you'll need to use the pageY and pageX variables/what ever they are. I don't suggest doing this, there are tones of scripts out there already. And one even made by me. I'm not gonna give this one because I gave a one from dd above. I really don't suggest doing it unless your doing it for the fun of it. If you are:
    pageY and pageX don't need events before them like clientY and clientX. They just need any variable. I suggest putting an `e` variable in the function, and making that e value event. Then before the client and page you'll put that e variable. If you know what I mean? Lol...
    Jeremy | jfein.net

  6. #6
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Oh, I've done it before. I'm just testing this stuff out because you said something was wrong.

    -magicyte

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •