SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I cannot move div by A, W, D, S keys

    Hi,

    I cannot move div by A, W, D, S keys: http://jsfiddle.net/8Observer8/mHAHz/128/

    Thank you!

  2. #2
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    13
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    1) You don't match the right keys. It might be browser specific, not sure with jQuery, but mine are different than what you input.

    ________________________________________________________

    2) You do
    Code:
    $('square')
    instead of
    Code:
    $('.square')
    Gotta match the class, not a
    Code:
    <square>
    ________________________________________________________

    3) You need to add a 'position' attribute to the square's css properties.


    Try this: http://jsfiddle.net/mHAHz/130/

  3. #3
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    @thetenfold ;

    cool.
    Quality codes are optimized and tested...
    Click here for inspiration..

  4. #4
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much! How to move continuously (very fast and continuously)?

  5. #5
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    13
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What do you mean continuously? back and forth? Use window.setInterval to find when it gets to either side and have it fade the opposite way.

  6. #6
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to move div how a "small car".

  7. #7
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by thetenfold
    What do you mean continuously? back and forth? Use window.setInterval to find when it gets to either side and have it fade the opposite way.
    I think this div needs to be moved like Link in Legend of Zelda. So instead, he probably needs to listen for repeated key events as the key is held down (the key keeps making new events while it is held down?).

    Probably the script is slow because for each key it's findgin .square again and again. It should be faster if .square is found once and saved into a variable. Before document.onkeydown event listener.

  8. #8
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)

  9. #9
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much! This is the example from your link: http://jsfiddle.net/bDMnX/7/ I wanted to make this. Thanks!


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
  •