web development blog(转)

Top 10 jQuery Mobile Code Snippets that you need to know

jQuery Mobile is a framework for mobile web apps and mobile websites with an aim to provide a unified user interface system across many mobile device platforms such iPhone, BlackBerry, Android and Windows Mobile. The framework is built on top of one of the most popular Javascript frameworks, jQuery.

Followings are some of the most useful code snippets that I’ve used in my recent web app developed using jQuery Mobile framework.

1. Disable truncation for list items and buttons

If your list item or button has a long text, it will be truncated automatically by jQuery Mobile. To disable this truncation, add “white-space: normal;” to the CSS selector in question.

For example, to disable truncation for buttons:

.ui-btn-text {
white-space: normal;
}

To disable truncation for list descriptions:

.ui-li-desc {
white-space: normal;
}

To enable truncation, set it to “white-space: nowrap;“.

2. Display a random background image on page load

jQuery Mobile has a number of page initialization events that you can use to trigger certain methods on page load. The following CSS + Javascript can be used to display a random background image every time a page is loaded.

CSS

.my-page  { background: transparent url(../images/bg.jpg) 0 0 no-repeat; }

.my-page.bg1 { background: transparent url(../images/bg-1.jpg) 0 0 no-repeat; }

.my-page.bg2 { background: transparent url(../images/bg-2.jpg) 0 0 no-repeat; }

.my-page.bg3 { background: transparent url(../images/bg-3.jpg) 0 0 no-repeat; }

Javascript

$(‘.my-page‘).live("pagecreate", function() {
	var randombg = Math.floor(Math.random()*4); // 0 to 3
	$(‘.my-page‘).removeClass().addClass(‘bg‘ + randombg);
});

3. Disable a button action

To disable a button action (for eg: from opening a page), add the following Javascript.

$(‘#home-button‘).button("disable");

And to re-enable it:

$(‘#home-button‘).button("enable");

4. Disable loading pop-up message

I find the loading pop-up message a bit annoying because it gets triggered everytime you load a different page. To disable this: add the following line of code into your JS file.

$.mobile.pageLoading(true);

By default, it is enabled like so:

$.mobile.pageLoading();

5. Create a custom theme

jQuery Mobile framework comes with 5 themes – Theme A, Theme B, Theme C, Theme D and Theme E. But you can easily create a new theme for your web app.

The steps to create a new theme:
1. Copy CSS for any theme from jQuery Mobile CSS file and paste it into your own CSS file.
2. Give your theme a name and rename the CSS selectors appropriately. Your theme name can be any alphabet character (a to z). So for example, if you copied Theme C, and you want to call your theme Theme Z, rename.ui-btn-up-c to .ui-btn-up-z.ui-body-c to .ui-body-z and so on.
3. Change colors and styles of your custom theme
4. To apply your custom theme z to any element, just set the data-theme attribute to z. For example:

<div data-role="page" data-theme="z">

6. Use a custom font

There are a few font-replacement methods available such as cufon, sIFR, FLIR, @font-face and Google Fonts API. When building a web app using jQuery Mobile, I found that @font-face method is the easiest method to work with and the performance is quite satisfactory. If you are interested in @font-face, here is a helpful tutorial with a demo on how to work with @font-face method.

7. Create an image-only button with no text

Sometimes, you may not want to have any text for your button but still use the rest of the features that comes with a button element. This is usually the case with a home button or an info button. To hide any text associated with the button, set data-iconpos attribute to “notext”. For example:

<a href="../index.html" data-icon="grid"
class="ui-btn-right" data-iconpos="notext">Home</a>

8. Open a link without using AJAX with page transitions

To open a link without using AJAX with page transitions (ie: reloading the full page the old-school way), set rel attribute to “external”.

<a href="../index.html" data-icon="grid"
class="ui-btn-right" rel="external">Home</a>

9. Remove an arrow from a list item

By default, jQuery Mobile framework adds an arrow next to every list item. To disable this, set data-icon attribute to “false” on the list item that you’d like the arrow to be removed.

<li data-icon="false"><a href="contact.html">Contact Us</a></li>

10. Set background color of a page

This may sound simple but it took me a few minutes to figure out how to apply a background color to a page without having it overwritten by jQuery Mobile CSS. Normally, you’d set a background color to body element but if you are using jQuery Mobile framework, you need to set it to ui-page class.

.ui-page {
background: #eee;
}

web development blog(转)

时间: 2024-08-27 08:43:20

web development blog(转)的相关文章

Flask Web Development - Flask 模板1 - 模板机制&Jinja2引擎

节选自PartI Chapter3,这个chapter主要讲模板工作原理,这里讲的就是Jinja2这个模板,另外还提到了Flask-Bootstrap及Flask-Moment两个插件,前者对Flask使用Bootstrap做了些封装,后者对moment.js做了些封装.内容较多,估计分开搞. 模板存在的意义 可维护性高的代码是结构良好且整洁的. 当用户在网站注册一个账户时,他在表单里填入邮箱跟密码,并点击提交按钮.在server端就收到一个包含这些数据的request,再由Flask分发到相应

Plan for Perl Web Development

Plan for Perl Web Development [2015/2/8 to 2015/4/1] Perl Foundation (Task::Kensho,DBDev: Database Development,XML: XML Development) Web Foundation (Task::Kensho::WebCrawling: Web Crawling) Web Development (Task::Kensho::WebDev: Web Development) Web

Flask Web Development - Flask插件机制&Flask-Script

本节取自part I chapter 2的后半部分,跳过了关于request与response具体交互设计细节内容.主要通过Flask-Script插件让读者对于插件系统有个简单认识. Flask注重拓展性,社区里已经有很多插件可供选择,当然也可以使用python标准库或者其他的各种库. Flask-Script Flask-Script这个插件,是用来增加Flask应用的命令行参数的,它本身自带了一些通用的选项,也支持自定义的命令.这功能可能类似于python标准库中的argparse. 之前

Learn Web.Development of Perl

##### #Overview of Web.Development related modules. #Note that, below codes can not be executed just for overview intention. ##### #!/usr/bin/perl #CGI::FormBuilder::Source::Perl #Dancer, A lightweight yet powerful web application framework #HTML::Fo

《Flask Web Development》学习笔记---chapter4 Web Forms

1.  我们用 wrapper了WTForms的Flask-WTF扩展来处理表单生成和验证. 2.  Cross-Site Request Forgery (CSRF) 保护 配置config,'SECRET_KEY' 3. Form class definition from flask.ext.wtf import Form from wtforms import StringField, SubmitField from wtforms.validators import Required

flask web development 阅读笔记

在flask应用中,所有的flask应用都必须创建一个应用实例.web服务器把它接收的来自客户端的请求通过WSGI的协议传递给这个对象以进行处理.这时候,它会提供一种叫上下文的神奇环境,它能让一些对象可以全局可见,这样你的视图函数就可以去访问这些对象做些处理,而又在同时有那么多请求时确保线程安全. flask里有两种上下文,应用上下文和请求上下文,这两种上下文里暴露出了4种变量: 应用上下文 current_app 活动应用程序的应用实例 应用上下文 g 在处理请求时临时存储数据,每次请求都会被

《Web Development with Go》JWT认证

时间晚了,先来一版调通的JWT普通认证, 明天再弄一个通过中间件,及gorilla,negroni库的认证, 这样正规些, 但认证通过之后,如何对应权限? 由于jwt-go从2升到3,还有rsa 1024加密有对应关系, 真的弄好好久. 一,生成rsa密钥对,必须1024 openssl genrsa -out app.rsa 1024 openssl rsa -in app.rsa -pubout > app.rsa.pub 二,jwt的初始化方法改变 t := jwt.New(jwt.Sig

《Web Development with Go》JWT认证满意版

这个比昨晚的要满意, 认证放到中间件那里了. Mux使用的是gorilla, 中间件使用的是negroni, 启动是用的negroni.classic方法. package main import ( "encoding/json" "fmt" "io/ioutil" "log" "net/http" "time" "github.com/codegangsta/negroni

&lt;flask web development&gt;学习记录

1 @app.route('/', methods=['GET', 'POST']) 2 def index(): 3 name = None 4 form = NameForm() #将form设置为NameForm类 5 if form.validate_on_submit(): #如果有数据提交的话 6 name = form.name.data #就让name=提交的数据 7 form.name.data = '' #并且把submit栏清空 8 return render_templa