javascript - jquery mobile panel events not firing - Stack Overflow

I can't seem to tie into the jquery mobile panel events as seen here .3.0-rc.1docspanelsevents.

I can't seem to tie into the jquery mobile panel events as seen here

.3.0-rc.1/docs/panels/events.html

$(document).on('beforeopen', ".ui-panel", function() {
    alert('open');
});
$(document).on('beforeclose', ".ui-panel", function() {
    alert('close');
 });

or

 $(document).on('open', ".ui-panel", function() {
    alert('open');
});
$(document).on('close', ".ui-panel", function() {
    alert('close');
 });

or even using context on the panel

$('.ui-panel',context).on('open', function() {
    alert('opened');
});

where context is a jquery object variable of the current page

I can't seem to tie into the jquery mobile panel events as seen here

http://jquerymobile./demos/1.3.0-rc.1/docs/panels/events.html

$(document).on('beforeopen', ".ui-panel", function() {
    alert('open');
});
$(document).on('beforeclose', ".ui-panel", function() {
    alert('close');
 });

or

 $(document).on('open', ".ui-panel", function() {
    alert('open');
});
$(document).on('close', ".ui-panel", function() {
    alert('close');
 });

or even using context on the panel

$('.ui-panel',context).on('open', function() {
    alert('opened');
});

where context is a jquery object variable of the current page

Share asked May 24, 2013 at 1:51 BrianBrian 4,41814 gold badges63 silver badges105 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

Taking a look at the jQuery mobile API

It provides examples for beforeopen(event, ui) which is a type of panelbeforeopen, they provide these examples in the API documentation:

1) Initialize the panel with the beforeopen callback specified:

$( ".selector" ).panel({
  beforeopen: function( event, ui ) {}
});

2) Bind an event listener to the panelbeforeopen event:

$( ".selector" ).on( "panelbeforeopen", function( event, ui ) {} );

you must insert your code inside $( document ).on( "pageinit", function( event, data ){.....

   $(document).on( "pageinit", function( event, data ){
     $( ".ui-panel" ).on( "panelbeforeclose", function( event, ui ) {
        // your code here
     } );
   });

You have to reference the correct div for it to work. Your selector needs to reference the div that has data-role="panel".

$(window).on("load",function(){

    $( "#your-panel-id" ).on( "panelclose", function( event, ui ) {
        alert ('hi') ;
    }); 
}); 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742405125a4437690.html

相关推荐

  • javascript - jquery mobile panel events not firing - Stack Overflow

    I can't seem to tie into the jquery mobile panel events as seen here .3.0-rc.1docspanelsevents.

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信