1. 程式人生 > >WEUI應用,用JS封裝常用資訊—ActionSheet

WEUI應用,用JS封裝常用資訊—ActionSheet

$(document).on("click","#showActionSheet",function(){ actionSheetMenu({id:'aa',text:'選單一'},{id:'bb',text:'選單二'},{id:'cc',text:'選單三'}); $('body').on('click','#aa',function(){ alert('選單一'); $('#actionsheet_cancel').trigger('click'); }); $('body').on('click'
,'#bb',function(){ alert('選單二'); }); $('body').on('click','#cc',function(){ location.href="http://www.baidu.com"; }); }); function actionSheetMenu(){ if(!arguments.length){ return; } var menuHtml = ''; for(i=0;i<arguments
.length;i++){ if(typeof(arguments[i]) != 'object' || !arguments[i].id || !arguments[i].text){ continue; } menuHtml += '<div class="weui_actionsheet_cell" id="' + arguments[i].id + '">' + arguments[i].text + '</div>'; } if(!menuHtml){ return
; } var actionSheetMenuStr; actionSheetMenuStr = '\ <div id="actionSheet_wrap">\ <div class="weui_mask_transition" id="mask"></div>\ <div class="weui_actionsheet" id="weui_actionsheet">\ <div class="weui_actionsheet_menu">\ </div>\ <div class="weui_actionsheet_action">\ <div class="weui_actionsheet_cell" id="actionsheet_cancel">取消</div>\ </div>\ </div>\ </div>\ '; if(!$('#actionSheet_wrap').length){ $('body').append(actionSheetMenuStr); } $('.weui_actionsheet_menu').html(menuHtml); $('#mask').show().addClass('weui_fade_toggle'); $('#weui_actionsheet').addClass('weui_actionsheet_toggle'); $('#mask').unbind('transitionend').unbind('webkitTransitionEnd'); $('#mask , #actionsheet_cancel').on('click',function(){ $('#mask').removeClass('weui_fade_toggle'); $('#weui_actionsheet').removeClass('weui_actionsheet_toggle'); $('#mask').on('transitionend webkitTransitionEnd',function(e){ $('#mask').hide(); }); }); }