Results 1 to 5 of 5

Thread: Transform coordinates (x,y) in pixels

  1. #1
    Join Date
    Apr 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Transform coordinates (x,y) in pixels

    Hey everybody!
    Im studying javascript, and I tried to make a script for a image follow the cursor. The script calculate the coordinate of the cursor, but I cant put a coordinate in a css (style.left = coordinate_x)

    What can I do?

    Thanks!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Either give us a link to your page or post the code here. It's too hard to guess what you are doing.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    Djr33 - he wants to make an image follow a cursor.

    I hope you're using client(X, Y) and page(X, Y) including additional things. Anyways - just change the css within the Javascript:
    Code:
    document.getElementById('element').style.position = "absolute";
    document.getElementById('element').style.left = posX;
    document.getElementById('element').style.top = posY;
    Jeremy | jfein.net

  4. #4
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    document.getElementById('element').style.position = "absolute";
    document.getElementById('element').style.left = posX+'px';
    document.getElementById('element').style.top = posY+'px';
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

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

    Default

    Aha - good point. Maybe parseInt() is also essential? I wouldn't know that much about this though.
    Jeremy | jfein.net

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
  •