Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can always get the position of the element: </p> <pre><code> $('#bird').position().top // left, right, bottom. </code></pre> <p>Then you can get the distance of that this sprite have with the object and set the correct spState.</p> <p>Something like:</p> <pre><code> distance = Math.sqrt(( Math.pow( (object.position().left - spirte.position().left), 2) + Math.pow( (object.position().top - spirte.position().left), 2) )); </code></pre> <p>So you can check with an if how much distance those things need to have to changue.</p> <p>Check <a href="http://api.jquery.com/category/offset/" rel="nofollow">this</a>.</p> <p>And <strong>for watch the sprite</strong> you need something like <a href="http://www.west-wind.com/weblog/posts/2011/Feb/22/A-jQuery-Plugin-to-monitor-Html-Element-CSS-Changes" rel="nofollow">this</a>, is a jQuery plugin that uses <strong><a href="https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Events/Mutation_events" rel="nofollow">Mutations Events</a></strong> for watch the elements, the <a href="http://www.west-wind.com/WestwindWebToolkit/docs/?page=_2hr18bqcy.htm" rel="nofollow">documentation</a>.</p> <p>Also now there's the <a href="https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver?redirectlocale=en-US&amp;redirectslug=DOM/MutationObserver" rel="nofollow">Mutation Observers</a> is a replace for the <strong><a href="https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Events/Mutation_events" rel="nofollow">Mutations Events</a></strong>, so you can write an observer for your DOM object, <a href="http://updates.html5rocks.com/2012/02/Detect-DOM-changes-with-Mutation-Observers" rel="nofollow">more here</a></p> <p><strong><a href="http://jsfiddle.net/auVY2/2/" rel="nofollow">Here's an example</a></strong> i hope it helps you make an idea.</p> <p><strong>Update</strong></p> <p>All you need to do is get the center of the parent, then check for the current position of your sprite and see if it's more or less than the center.</p> <p><a href="http://jsfiddle.net/auVY2/3/" rel="nofollow">Left or Rigth</a></p> <p><strong>Update 2</strong></p> <p>It seems to work outside jsfiddle. <a href="http://jsbin.com/ipijos/2/" rel="nofollow">Test it here.</a> (jsbin)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload