读书人

您需要了解的 10 个 jQuery mobile 贴

发布时间: 2012-09-20 09:36:50 作者: rapoo

你需要了解的 10 个 jQuery mobile 贴士和代码片段

1. 一个完整的基本页面

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Page Title</title>
  5. <link?rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
  6. <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
  7. <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
  8. </head>
  9. <body>
  10. <div data-role="page" id="home">
  11. <div data-role="header">
  12. ??<h1>Header</h1>
  13. </div>
  14. <div data-role="content">
  15. ??<p>Content goes here</p>
  16. </div>
  17. <div data-role="footer">
  18. ??<h4>Footer</h4>
  19. </div>
  20. </div>
  21. </body>
  22. </html>
复制代码

您需要了解的 10 个 jQuery mobile 贴士和代码片段?


2. 在什么地方添加?jQuery?的方法调用?
  1. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
  2. <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
  3. <script>
  4. $(document).ready(function() {
  5. ??// 在这里添加 jQuery 代码
  6. });
  7. </script>
  8. <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
复制代码

您需要了解的 10 个 jQuery mobile 贴士和代码片段?


3. 一次性禁用所有链接的 Ajax 导航
  1. <script>
  2. $(document).ready(function() {
  3. ??// disable ajax nav
  4. ??$.mobile.ajaxLinksEnabled =?false;
  5. });
  6. </script>
复制代码

您需要了解的 10 个 jQuery mobile 贴士和代码片段



4. 防止某些关键条目被截断

某些比较长的条目会被自动截断并使用 ... 替换显示,该方法可避免出现这种情况

列表项:

?

  1. body .ui-li .ui-li-desc {
  2. white-space: normal;
  3. }
复制代码

?

For footer content:

?

  1. body .ui-footer .ui-title {
  2. white-space: normal;
  3. }
复制代码

?

5. Use media queries to target devices

One of the first questions I had with this library was how to target devices in the CSS (based on screen size). For example, I wanted a two-column layout for the iPad and a single column for smartphones. The absolute best way to accomplish this is with media queries.

With some simple media queries in place, you can quickly make the CSS target screen sizes. And with this type of targeting, we can quickly set up different layouts based on the available screen space by relying on conventional CSS techniques.

Two fantastic resources for this are:

读书人网 >移动开发

热点推荐