偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

使用jQuery Mobile框架將博客快速轉(zhuǎn)化為Mobile網(wǎng)站

移動(dòng)開(kāi)發(fā) 移動(dòng)應(yīng)用
jQuery Mobile是一個(gè)非常不錯(cuò)的移動(dòng)端網(wǎng)站應(yīng)用的解決方案,很多網(wǎng)站都使用jQuery Mobile來(lái)生成Mobile手機(jī)端的移動(dòng)網(wǎng)站應(yīng)用,在過(guò)去的GBin1博客文章中,我們?cè)?jīng)使用jQuery Mobile利用RSS訂閱生成過(guò)一個(gè)簡(jiǎn)單的RSS閱讀手機(jī)端,在今天的教程中,我們將講解如何將GBin1網(wǎng)站完整的轉(zhuǎn)化為一個(gè)全功能的移動(dòng)端網(wǎng)站,主要的技術(shù)使用jQuery Mobile和Java的SiteMesh布局類(lèi)庫(kù)

使用jQuery Mobile移動(dòng)開(kāi)發(fā)框架將博客網(wǎng)站快速轉(zhuǎn)化為Mobile網(wǎng)站

在線(xiàn)演示

jQuery Mobile是一個(gè)非常不錯(cuò)的移動(dòng)端網(wǎng)站應(yīng)用的解決方案,很多網(wǎng)站都使用jQuery Mobile來(lái)生成Mobile手機(jī)端的移動(dòng)網(wǎng)站應(yīng)用,在過(guò)去的GBin1博客文章中,我們?cè)?jīng)使用jQuery Mobile利用RSS訂閱生成過(guò)一個(gè)簡(jiǎn)單的RSS閱讀手機(jī)端,在今天的教程中,我們將講解如何將GBin1網(wǎng)站完整的轉(zhuǎn)化為一個(gè)全功能的移動(dòng)端網(wǎng)站,主要的技術(shù)使用jQuery Mobile和Java的SiteMesh布局類(lèi)庫(kù)

系統(tǒng)設(shè)計(jì)分析

在我們正式的開(kāi)始開(kāi)發(fā)之前,我們需要大概的分析一下如何設(shè)計(jì)Mobile網(wǎng)站,很多網(wǎng)站的移動(dòng)端應(yīng)用和網(wǎng)站的內(nèi)容是分離的,也就是說(shuō),桌面訪問(wèn)網(wǎng)站和移動(dòng)設(shè)備訪問(wèn)網(wǎng)站的路徑是不同的。

  • 好處是可以分別開(kāi)發(fā)獨(dú)立的功能,我們可以針對(duì)移動(dòng)端的用戶(hù)設(shè)計(jì)獨(dú)立的UI,展現(xiàn)方式,或者使用方式,往往對(duì)于比較大型的網(wǎng)站或者已經(jīng)上線(xiàn)很久的網(wǎng)站這樣設(shè)計(jì)成本比較低。
  • 壞處是你需要獨(dú)立的維護(hù)兩套代碼,無(wú)形的增加了開(kāi)發(fā)成本和維護(hù)成本 

在我們GBin1的移動(dòng)設(shè)備網(wǎng)站開(kāi)發(fā)中,我們本著盡量維護(hù)同一套代碼的原則,希望能夠直接重用網(wǎng)站的頁(yè)面內(nèi)容和框架。值得一提的是,GBin1架 構(gòu)使用Sitemesh的模板布局功能來(lái)生成頁(yè)面的不同樣式和布局,而相關(guān)的頁(yè)面內(nèi)容及其附屬功能,例如,留言等等都是由靜態(tài)頁(yè)面或者功能模塊生成,這樣 的設(shè)計(jì)使得我們可以利用已經(jīng)存在的頁(yè)面內(nèi)容花最小的代價(jià)來(lái)創(chuàng)建新的移動(dòng)設(shè)備模板,因而可以快速的生成新的移動(dòng)端web應(yīng)用,而且整體結(jié)構(gòu)及其閱讀使用方式 將會(huì)和網(wǎng)站本身的使用方式類(lèi)似,降低了用戶(hù)的學(xué)習(xí)成本。

如何實(shí)現(xiàn)?

為了讓系統(tǒng)能夠自動(dòng)處理應(yīng)用不同的模板,這里我們使用了一個(gè)小技巧:

我們創(chuàng)建一個(gè)2級(jí)域名, 例如, http://m.gbin1.com,將它通過(guò)域名綁定了我們的服務(wù)器。然后通過(guò)后臺(tái)的應(yīng)用來(lái)判斷當(dāng)前的域名訪問(wèn),如果用戶(hù)通過(guò)http://www.gbin1.com來(lái)訪問(wèn)的話(huà),我們將應(yīng)用網(wǎng)站模板,如果用戶(hù)嘗試使用http://m.gbin1.com來(lái)訪問(wèn)gbin1的時(shí)候,我們將使用移動(dòng)設(shè)備模板來(lái)展示網(wǎng)站內(nèi)容。通過(guò)這種方法,系統(tǒng)能夠自動(dòng)的應(yīng)用不同的模板生成不同的web應(yīng)用界面。

當(dāng)然,我們也可以做的更好,自動(dòng)判斷客戶(hù)端的代理類(lèi)型,如果是移動(dòng)設(shè)備,自動(dòng)重定向到http://m.gbin1.com,否則重定向到http://www.gbin1.com。

代碼實(shí)現(xiàn)

設(shè)計(jì)和實(shí)現(xiàn)基本完成以后,我們正式開(kāi)始開(kāi)發(fā)網(wǎng)站的移動(dòng)設(shè)備模板,使用jQuery Mobile框架。使用jQuery Mobile框架的好處在于,考慮了不同手機(jī)的兼容性并且封裝了現(xiàn)成的UI組件,我們只需要簡(jiǎn)單的添加幾個(gè)html標(biāo)簽即可生成對(duì)應(yīng)的頁(yè)面,如下:

  1. <div data-role="page"> 
  2.     <div data-role="header"> 
  3.         <a href="/bloghome.html" data-icon="help">首頁(yè)</a> 
  4.         <h1 id="logo"></h1> 
  5.         <a href="/portfolio/" data-icon="info">關(guān)于</a> 
  6.         <div data-role="navbar" data-iconpos="top" data-theme="a"> 
  7.             <nav> 
  8.  
  9.             </nav> 
  10.         </div><!-- /navbar --> 
  11.     </div><!-- /header --> 
  12.  
  13.     <div data-role="content">    
  14.  
  15.     </div><!-- /content --> 
  16.  
  17.     <div data-role="footer">  
  18.         <h4>&copy; Copywrite by gbin1.com, all rights reserved.</h4>  
  19.     </div>  
  20. </div><!-- /page --> 

以上代碼我們定義了,頁(yè)頭,內(nèi)容和頁(yè)腳。

在頁(yè)頭中我們添加了兩個(gè)按鈕, 首頁(yè)和關(guān)于

頁(yè)腳中我們添加了版權(quán)相關(guān)信息。

生成頁(yè)面內(nèi)容如下:

m.gbin1.com

為了更好在不同的移動(dòng)設(shè)備上看到展示效果,這里我們使用一個(gè)在線(xiàn)測(cè)試響應(yīng)式設(shè)計(jì)的web工具- Screenqueri.es,使用它能夠幫助你在不同的移動(dòng)設(shè)備上查看網(wǎng)站效果,同時(shí)它支持本地localhost應(yīng)用查看效果,支持不同設(shè)備上的預(yù)覽,例如,iphone,ipad及其其它設(shè)備,并且支持橫豎屏切換,所以對(duì)于我們?cè)诰€(xiàn)調(diào)試非常有幫助。

添加相關(guān)代碼

接下里我們需要添加一些相關(guān)代碼來(lái)處理移動(dòng)設(shè)備中的顯示,包括:

  • 圖片
  • 視頻
  • 其它

因?yàn)椴煌脑O(shè)備的顯示界面尺寸不一樣,為了能夠在小尺寸的設(shè)備上正常的顯示頁(yè)面,我們需要在加載頁(yè)面之前,處理相關(guān)圖片,或者視頻的尺寸大小。代碼如下:

  1. $(document).bind('pageinit' , function(){ 
  2.  
  3.     $('img').css({ 
  4.         'max-width':'280px'
  5.         'height':'auto' 
  6.     }); 
  7.  
  8. }); 

注意我們?cè)谝陨洗a中調(diào)用了css方法來(lái)處理圖片,這里為了簡(jiǎn)單,我們直接將圖片設(shè)置為最大寬大為280px,如果你需要支持不同的設(shè)備,你可以根據(jù)設(shè)備不同,處理不同的圖片寬度。

再 請(qǐng)注意這里我們使用了pageinit方法,在正常的jQuery開(kāi)發(fā)中,我們一般使用document.ready() 方法來(lái)處理,但是對(duì)于jQuery mobile來(lái)說(shuō),當(dāng)頁(yè)面導(dǎo)航的時(shí)候Ajax被用來(lái)加載頁(yè)面內(nèi)容,所以DOM ready方法只存在于第一個(gè)加載頁(yè)面,為了能夠讓每一個(gè)頁(yè)面都可以執(zhí)行代碼,所以我們需要在頁(yè)面初始化(pageinit)方法中調(diào)用相關(guān)方法,否則你 會(huì)看到除了第一個(gè)頁(yè)面外以后其它頁(yè)面的圖片沒(méi)有任何變化。

如果你有其它的代碼需要在也頁(yè)面中調(diào)用的話(huà),你同樣也可以加載到上面的方法中去。如下:

  1. $(document).bind('pageinit' , function(){ 
  2.  
  3.     $('img').css({ 
  4.         'max-width':'280px'
  5.         'height':'auto' 
  6.     }); 
  7.  
  8.     $('a').each(function(){ 
  9.         var url = $(this).attr('href'); 
  10.         var laststr = url.lastIndexOf(".html"); 
  11.         var lastc = url.charAt(url.length-1); 
  12.         var startc = url.charAt(0); 
  13.         if(laststr<0&&lastc!=='/'&&startc!=='?'){ 
  14.             $(this).attr('href'url + '/'); 
  15.         } 
  16.     }); 
  17.  
  18. }); 

在我們的代碼中,我們需要處理圖片及其url中的地址問(wèn)題,所以我們將相關(guān)的代碼放置到pageinit中。

完整模板代碼如下:

  1. <!DOCTYPE html> 
  2. <!-- By GBin1.com--> 
  3. <%@ page contentType="text/html;charset=utf-8"%> 
  4. <%@ taglib uri="gbin1cms-taglib" prefix="cms" %> 
  5.  
  6. <jsp:useBean id="userInfo" scope="session" class="com.gbin1.core.UserInfo" /> 
  7. <jsp:useBean id="webSite" scope="request" type="com.gbin1.core.WebSite" /> 
  8.  
  9. <html> 
  10. <head> 
  11.         <title><cms:pagetitle /></title> 
  12.         <meta name="description" content="<cms:info id="description" />" /> 
  13.         <meta name="keywords" content="<cms:info id="keywords" />" /> 
  14.         <meta name="author" content="<cms:info id="author" /> (<cms:info id="authorurl" />)" />      
  15.         <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" /> 
  16.         <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 
  17.         <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> 
  18.         <cms:pagehead />  
  19.         <style> 
  20.             #logo{ 
  21.                 background: url('/gbin1/themes/gbin1_mobile/images/logo.png') no-repeat 50% 50%; 
  22.                 height: 30px; 
  23.             } 
  24.  
  25.             #navlist{ 
  26.                 font-size:14px; 
  27.             } 
  28.  
  29.             .ui-btn-text{ 
  30.                 font-size:12px; 
  31.             } 
  32.  
  33.             H1,H2,H3,H4,H5,H6,H7,H8,H9,H10{ 
  34.                 font-size:14px; 
  35.             } 
  36.  
  37.             .ui-header .ui-title{ 
  38.                 font-size:14px; 
  39.             } 
  40.  
  41.             .ui-footer .ui-title{ 
  42.                 font-size:12px; 
  43.                 font-weight: normal; 
  44.             } 
  45.  
  46.             .ui-body-c .ui-link { 
  47.                 text-decoration: none; 
  48.                 font-size:14px; 
  49.                 font-weight: normal; 
  50.             } 
  51.             .ui-btn-text{ 
  52.                 font-weight: normal; 
  53.             } 
  54.             .ui-body-c{ 
  55.                 font-size:14px; 
  56.                 line-height: 20px; 
  57.             } 
  58.             .includetitle{ 
  59.                 background: #E1E1E1; 
  60.                 padding: 5px 5px; 
  61.                 border-left: 3px solid #BBB; 
  62.                 border-radius: 3px 3px 3px 3px; 
  63.             } 
  64.  
  65.             .includenavigation .ui-link, .includenavigation .ui-link:visited{ 
  66.                 color: #ffffff; 
  67.                 text-shadow: 0px 0px 20px #CCC; 
  68.             } 
  69.  
  70.             .includereadmore{ 
  71.                 text-align: right; 
  72.                 padding: 5px; 
  73.                 width: auto; 
  74.                 border-top: 1px solid #CCC; 
  75.             } 
  76.  
  77.             .includenavigation{ 
  78.                 color: #909090; 
  79.                 font-weight: bold; 
  80.             } 
  81.         </style> 
  82.         <script>             
  83.  
  84.             $(document).bind('pageinit' , function(){ 
  85.  
  86.                 $('img').css({ 
  87.                     'max-width':'280px', 
  88.                     'height':'auto' 
  89.                 }); 
  90.  
  91.                 $('a').each(function(){ 
  92.                     var url = $(this).attr('href'); 
  93.                     var laststr = url.lastIndexOf(".html"); 
  94.                     var lastc = url.charAt(url.length-1); 
  95.                     var startc = url.charAt(0); 
  96.                     if(laststr<0&&lastc!=='/'&&startc!=='?'){ 
  97.                         $(this).attr('href', url + '/'); 
  98.                     } 
  99.                 }); 
  100.  
  101.             }); 
  102.         </script> 
  103. </head> 
  104. <body> 
  105. <cms:editor>    
  106. <div data-role="page"> 
  107.     <div data-role="header"> 
  108.         <a href="/bloghome.html" data-icon="help"><%=new String("\u9996\u9875")%></a> 
  109.         <h1 id="logo"></h1> 
  110.         <a href="/portfolio/" data-icon="info"><%=new String("\u5173\u4e8e")%></a> 
  111.         <div data-role="navbar" data-iconpos="top" data-theme="a"> 
  112.             <nav> 
  113.                 <cms:listmenu style="listview" path="root" items="firstlevel" current="link" currentStyle="current" currentPathStyle="ui-btn-active"/> 
  114.             </nav> 
  115.         </div><!-- /navbar --> 
  116.     </div><!-- /header --> 
  117.  
  118.     <div data-role="content">    
  119.         <cms:moduletitle location="left1" /> 
  120.         <cms:ifmodule location="left1"> 
  121.             <cms:module location="left1" alt="left1" /> 
  122.         </cms:ifmodule> 
  123.         <cms:pagebody /> 
  124.     </div><!-- /content --> 
  125.  
  126.     <div data-role="footer">  
  127.         <h4>&copy; Copywrite by gbin1.com, all rights reserved.</h4>  
  128.     </div>  
  129. </div><!-- /page --> 
  130.  
  131. </cms:editor> 
  132. <!-- google and baidu code  
  133. <script type="text/javascript"> 
  134.   var _gaq_gaq = _gaq || []; 
  135.   _gaq.push(['_setAccount', 'UA-19118450-1']); 
  136.   _gaq.push(['_trackPageview']); 
  137.   (function() { 
  138.     var ga = document.createElement('script'); ga.type = 'text/javascript'ga.async = true
  139.     ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
  140.     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
  141.   })(); 
  142. </script> 
  143. <script type="text/javascript"> 
  144. var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); 
  145. document.write(unescape("%3Cscript src='" + _bdhmProtocol + "#/h.js%3Fd999331ad5ea0c0930f3aa7c3bda9fc1' type='text/javascript'%3E%3C/script%3E")); 
  146. </script> 
  147. <!-- end of google and baidu code -->    
  148. </body> 
  149. </html> 

搞定!從上面代碼中我們可以看到,使用模板化的網(wǎng)站設(shè)計(jì)對(duì)于添加jQuery mobile移動(dòng)web網(wǎng)站非常重要,你只需要替換CSS,并且將所有的jQuery Mobile的處理代碼放置到模板中即可,基本無(wú)須修改其它結(jié)構(gòu),即可看到效果。

當(dāng)然,整個(gè)頁(yè)面的樣式和風(fēng)格可能差強(qiáng)人意,不過(guò)我們會(huì)在以后的文章中,會(huì)教大家如何將mobile web應(yīng)用修改的更好,例如,修改缺省的UI樣式,添加搜索功能等等。

責(zé)任編輯:佚名 來(lái)源: GBin1.com
相關(guān)推薦

2011-07-21 14:57:34

jQuery Mobi

2012-11-15 10:18:51

IBMdw

2011-07-19 14:51:54

jQuery Mobi特性

2011-09-02 10:41:51

2011-09-05 13:45:25

jQuery MobiSencha Touc移動(dòng)Web UI框架

2012-10-09 09:28:48

jQuery Mobi餐廳訂餐應(yīng)用

2011-09-01 10:16:43

JQuery Mobi

2011-09-05 16:43:00

jQuery Mobi

2011-05-26 16:28:08

Android jQuery

2011-09-01 10:21:52

jQuery Mobi元素

2011-07-19 17:09:44

jQuery Mobi事件

2011-07-21 16:10:11

button按鈕jQuery Mobi

2011-07-20 14:11:24

響應(yīng)布局jQuery Mobi

2009-02-17 12:38:21

OperaMobile Linu瀏覽器

2011-07-06 16:26:32

jQuery Mobi

2011-09-06 16:16:48

jQuery Mobi

2011-09-01 15:00:48

jQuery MobiDemo

2011-09-01 10:27:42

jQuery Mobi

2011-09-05 16:47:49

jQuery Mobi

2011-07-19 15:01:16

jQuery Mobi易用性
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)