Wednesday, March 21, 2012

jQuery mobile events

Events in jQuery Mobile are:

  1. tap
  2. taphold
  3. swipe
  4. swipeleft
  5. swiperight
  6. orientationchange
  7. scrollstart
  8. scrollstop
  9. pagebeforeshow
  10. pagebeforehide
  11. pageshow
  12. pagehide
  13. pagebeforecreate
  14. pagecreate
  15. vmouseover
  16. vmousedown
  17. vmousemove
  18. vmouseup
  19. vclick
  20. vmousecancel

 
 

One may bind to these events as one would to any other. And by bind, I mean this stuff:

  1. $('#foo').bind('click', function() {
       alert($(this).text());
    });
  2. $('#bar').live('click', function() {
       alert($(this).text());
    });
  3. $("table").delegate("td", "hover", function(){
       $(this).toggleClass("hover");
    });
  4. bind effects immediate entities
  5. live effects those that may appear later too
  6. it seems delegate takes three parameters
  7. delegate is a marginally more performant version of live
  8. delegate must be declared before the thing it effects comes into memory (I think)

 
 

Binding to pageCreate() or pageInit() like this may be wise...

$('#foo').live('pagecreate', function(event) {
   alert($(this).text());
});

 
 

...as this yells:

Important: Use pageCreate(), not $(document).ready()

No comments:

Post a Comment