Jquery Mobile 自定義按鈕圖標(biāo)
很多朋友都反應(yīng)jquery mobile自帶的圖標(biāo)真的是少之又少,另外我也覺得圖標(biāo)偏小(系統(tǒng)自帶的是18*18的),于是琢磨著如何自定義按鈕圖標(biāo),下面小編把我的方法分享給大家。
剛接觸Jquery Mobile框架,遇到個很現(xiàn)實問題,就是如何自定義按鈕圖標(biāo),我覺得jquery mobile 自帶的圖標(biāo)實在是太少了,另外我覺得圖標(biāo)也偏?。ㄏ到y(tǒng)自帶的應(yīng)該是18*18的)下面是我的方法,希望大家踴躍拍磚。
1、第一種方法是比較簡單的,但是有前提,前提就是你自定義的圖標(biāo)大小應(yīng)該和系統(tǒng)內(nèi)置的保持一致,這樣排版上才不會出問題,具體方法如下:
首先定義css文件
.ui-icon-email{
background:url('./images/email.png') no-repeat 0px 0px;
}
data-icon="email"
就可以了。
2、第二種方法,這種方法適合自定義圖標(biāo)大小和系統(tǒng)不一致的情況,閑話不說了,先上效果圖,

3、代碼如下:
【css代碼】
/** 圖標(biāo)大小 **/
.user-ui-btn .ui-icon{
width:36px;
height:36px;
}
/** 設(shè)置字體大小,由于圖標(biāo)變大,所以文字適當(dāng)?shù)恼{(diào)大一些 **/
.user-ui-btn .ui-btn-text{
line-height:36px;
font-size:20px;
}
/** 無文字按鈕 **/
.user-ui-btn .ui-btn-icon-notext{
width:42px;
height:42px;
webkit-border-radius: 2em;
border-radius: 2em;
}
/** 圖標(biāo)左邊 **/
.user-ui-btn .ui-btn-icon-left .ui-btn-inner {
padding-left: 50px;
}
.user-ui-btn .ui-btn-icon-left .ui-icon{
left:10px;
margin-top: -18px;
}
/** 圖標(biāo)在右邊 **/
.user-ui-btn .ui-btn-icon-right .ui-btn-inner {
padding-right: 50px;
}
.user-ui-btn .ui-btn-icon-right .ui-icon{
right:10px;
margin-top: -18px;
}
/** 圖標(biāo)在上邊 **/
.user-ui-btn .ui-btn-icon-top .ui-btn-inner {
padding-top: 50px;
}
.user-ui-btn .ui-btn-icon-top .ui-icon{
top:10px;
margin-left: -18px;
}
/** 圖標(biāo)在下邊 **/
.user-ui-btn .ui-btn-icon-bottom .ui-btn-inner {
padding-bottom: 50px;
}
.user-ui-btn .ui-btn-icon-bottom .ui-icon{
bottom:10px;
margin-left: -18px;
}
/** 定義自己的圖標(biāo) **/
.user-ui-btn .ui-icon-demo1{
background:url('./images/gentleface_full.png') no-repeat -108px 0px;
}
.user-ui-btn .ui-icon-demo2{
background:url('./images/gentleface_full.png') no-repeat -180px -180px;
}
.user-ui-btn .ui-icon-demo3{
background:url('./images/gentleface_full.png') no-repeat -252px -360px;
}
.user-ui-btn .ui-icon-demo4{
background:url('./images/gentleface_full.png') no-repeat -36px -180px;
}
.user-ui-btn .ui-icon-demo5{
background:url('./images/gentleface_full.png') no-repeat -504px -612px;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="js/jquery.mobile-1.3.2.css" />
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile-1.3.2.js"></script>
<link rel="stylesheet" type="text/css" href="js/demo.mobile-1.0.css" />
</head>
<body>
<div data-role="page" id="page">
<div data-role="header">
<h1>Jquery Mobile自定義按鈕</h1>
</div>
<div data-role="content">
<h2>原版樣式舉例</h2>
<div>
<a href="#" data-role="button" data-icon="home" data-inline="true" data-iconpos="left">DEMO</a>
<a href="#" data-role="button" data-icon="home" data-inline="true" data-iconpos="top">DEMO</a>
<a href="#" data-role="button" data-icon="home" data-inline="true" data-iconpos="right">DEMO</a>
<a href="#" data-role="button" data-icon="home" data-inline="true" data-iconpos="bottom">DEMO</a>
<a href="#" data-role="button" data-icon="home" data-inline="true" data-iconpos="notext">DEMO</a>
</div>
<h2>自定義樣式舉例</h2>
<h3>1)普通按鈕</h3>
<div class="user-ui-btn">
<a class="user-ui-btn" href="#" data-role="button" data-icon="demo1" data-inline="true" data-iconpos="left">DEMO</a>
<a class="user-ui-btn" href="#" data-role="button" data-icon="demo2" data-inline="true" data-iconpos="top">DEMO</a>
<a class="user-ui-btn" href="#" data-role="button" data-icon="demo3" data-inline="true" data-iconpos="right">DEMO</a>
<a class="user-ui-btn" href="#" data-role="button" data-icon="demo4" data-inline="true" data-iconpos="bottom">DEMO</a>
<a class="user-ui-btn" href="#" data-role="button" data-icon="demo5" data-inline="true" data-iconpos="notext">DEMO</a>
</div>
<h3>2)按鈕組</h3>
<div class="user-ui-btn" data-role="controlgroup" data-type="horizontal">
<a data-role="button" data-icon="demo1" data-iconpos="top">js</a>
<a data-role="button" data-icon="demo2" data-iconpos="top">css</a>
<a data-role="button" data-icon="demo3" data-iconpos="top">html</a>
<a data-role="button" data-icon="demo4" data-iconpos="top">ps</a>
</div>
<div class="user-ui-btn" data-role="controlgroup">
<a data-role="button" data-icon="demo1" data-iconpos="top">js</a>
<a data-role="button" data-icon="demo2" data-iconpos="top">css</a>
<a data-role="button" data-icon="demo3" data-iconpos="top">html</a>
<a data-role="button" data-icon="demo4" data-iconpos="top">ps</a>
</div>
<h3>3)原始icon</h3>
<img src="./js/images/gentleface_full.png" alt="原始icon" border=0 width=612 height=648>
</div>
<div data-role="footer">
<h4>Copyright by lining</h4>
</div>
</div>
</body>
</html>
以上內(nèi)容就是本文給大家講解的關(guān)于Jquery Mobile 自定義按鈕圖標(biāo)的實現(xiàn)方法,希望大家喜歡。
- jQuery Mobile彈出窗、彈出層知識匯總
- 使用jQueryMobile實現(xiàn)滑動翻頁效果的方法
- jquery Mobile入門—多頁面切換示例學(xué)習(xí)
- jQuery Mobile開發(fā)中日期插件Mobiscroll使用說明
- jquery mobile動態(tài)添加元素之后不能正確渲染解決方法說明
- 讓jQuery Mobile不顯示討厭loading界面的方法
- jquery mobile頁面跳轉(zhuǎn)后樣式丟失js失效的解決方法
- jquery Mobile入門—外部鏈接切換示例代碼
- jquery mobile changepage的三種傳參方法介紹
- jQueryMobile之Helloworld與頁面切換的方法
- jQueryMobile之窗體長內(nèi)容的缺陷與解決方法實例分析
相關(guān)文章
jquery Ajax 實現(xiàn)加載數(shù)據(jù)前動畫效果的示例代碼
本篇文章主要是對jquery Ajax實現(xiàn)加載數(shù)據(jù)前動畫效果的示例代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02
jquery如何把參數(shù)列嚴(yán)格轉(zhuǎn)換成數(shù)組實現(xiàn)思路
某參數(shù)的列只有一個參數(shù),那么each是失敗,如何保證pp嚴(yán)格是數(shù)組呢,很簡單var a=[pp];這一句就行了,感興趣的朋友可以參考下哈,希望可以幫助到你2013-04-04
jquery <li>標(biāo)簽 隔若干行加空白或者加虛線的方法
下面小編就為大家?guī)硪黄猨query <li>標(biāo)簽 隔若干行加空白或者加虛線的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12
jQuery代碼實現(xiàn)圖片墻自動+手動淡入淡出切換效果
在網(wǎng)頁上經(jīng)??梢钥吹接斜尘皥D片可以自動淡入淡入切換的效果,非常漂亮,實用性也非常高,今天小編給大家分享基于jquery代碼實現(xiàn)圖片墻自動+手動淡入淡出切換效果,感興趣的朋友一起學(xué)習(xí)吧2016-05-05
jquery實現(xiàn)很酷的網(wǎng)頁頂部圖標(biāo)下拉菜單效果
這篇文章主要介紹了jquery實現(xiàn)很酷的網(wǎng)頁頂部圖標(biāo)下拉菜單效果,效果非常美觀大方,通過鼠標(biāo)hover事件及頁面元素的遍歷與樣式操作實現(xiàn)該功能,需要的朋友可以參考下2015-08-08

