jQuery Mobile教程:jQuery Mobile基本事件

本文我们来认识一下jQuery Mobile的几个比较重要的基本事件

1、mobileinit

可以利用它来扩展$.mobile或者修改默认配置

示例:

<script type="text/javascript"> 
//方式1:绑定mobileinit
$(document).bind("mobileinit",function(e){ 	
//修改activePageClass 	
$.mobile.activePageClass = "custom-ui-page-active";  	
//增加一个自定义属性 	
$.mobile.version_inner = "zhang01"; });  
 
//方式2:绑定mobileinit 
$(document).bind("mobileinit",function(e){ 	
//增加一个自定义属性 	
$.extend(
$.mobile,{ activePageClass:"custom-ui-page-active",version_inner:"zhang01";}); }
); 
</script>  
//自定义脚本需要在依赖前面 <script src="http://www.w3cplus.com/sites/default/files/styles/print_image/public/jqm/../js/jquery.mobile-1.1.0.js" type="text/javascript"></script>

说明:
1、对mobileinit的绑定事件需要在引入jquery.mobile.js之前
2、扩展的方式有两种哦

2、$.mobile.loadPage(url,[options])

将某个页面加载到当前页面中,并自动对其增强

示例:

//给按钮绑定tap事件 //调用loadPage,载入contact.html 
$("#loadContact").live("tap",function(){ $.mobile.loadPage("contact.html"); });

关于loadPage的默认参数如图:

$.mobile.loadPage.defaults

说明:
1、loadPage只是载入到DOM中,不会显示

3、$.mobile.changePage(toPage,[options])

替换当前页面

参数toPage:文件URL或者内部的ID

示例:

//给按钮绑定tap事件 
$("#loadCopyright").live("tap",function(){ 	
//调用changePage,显示一个已经在DOM的id为copyright的page 	
$.mobile.changePage("#copyright");  	
//调用changePage,显示一个contact.html 	
$.mobile.changePage("contact.html"); });

关于changePage的默认参数如图:

$.mobile.changePage.defaults

说明:
1、changePage的第一个参数可以使

4、$.mobile.showPageLoadingMsg(theme,msgText,textonly)

弹出提示信息

参数theme:主题
参数msgText:提示文案内容
参数textonly:是否只显示文案

示例:

//给按钮绑定tap事件 
$("#showPageLoadingMsg").live("tap",function(){ 	
$.mobile.showPageLoadingMsg("e","自定义提示,主题e",true); 
});

5、$.mobile.hidePageLoadingMsg()

关闭提示信息

示例:

//hidePageLoadingMsg 
$("#hidePageLoadingMsg").live("tap",function(){ 	
$.mobile.hidePageLoadingMsg(); 
});

6、$.mobile.silentScroll(number)

垂直滚动number,不会触发scrollstart和scrollstop

示例:

//给按钮绑定tap事件 //silentScroll 
$("#silentScroll").live("tap",function(){ $.mobile.silentScroll(300); });

7、滚动事件:

1、给window绑定scrollstart事件:

示例:

$(window).scrollstart(function(e){ 	
var scrollTop = $(e.target).scrollTop(); 	
$("#scrollinfo").text("scrollstart:"+scrollTop);
});

2、给window绑定scrollstop事件:

示例:

$(window).scrollstop(function(e){ 	
var scrollTop = $(e.target).scrollTop(); 	
$("#scrollinfo").text("scrollstop:"+scrollTop); 
});

demo

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值