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

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;
}
/** 無(wú)文字按鈕 **/
.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)的實(shí)現(xiàn)方法,希望大家喜歡。
- jQuery Mobile彈出窗、彈出層知識(shí)匯總
- 使用jQueryMobile實(shí)現(xiàn)滑動(dòng)翻頁(yè)效果的方法
- jquery Mobile入門(mén)—多頁(yè)面切換示例學(xué)習(xí)
- jQuery Mobile開(kāi)發(fā)中日期插件Mobiscroll使用說(shuō)明
- jquery mobile動(dòng)態(tài)添加元素之后不能正確渲染解決方法說(shuō)明
- 讓jQuery Mobile不顯示討厭loading界面的方法
- jquery mobile頁(yè)面跳轉(zhuǎn)后樣式丟失js失效的解決方法
- jquery Mobile入門(mén)—外部鏈接切換示例代碼
- jquery mobile changepage的三種傳參方法介紹
- jQueryMobile之Helloworld與頁(yè)面切換的方法
- jQueryMobile之窗體長(zhǎng)內(nèi)容的缺陷與解決方法實(shí)例分析
相關(guān)文章
jquery Ajax 實(shí)現(xiàn)加載數(shù)據(jù)前動(dòng)畫(huà)效果的示例代碼
本篇文章主要是對(duì)jquery Ajax實(shí)現(xiàn)加載數(shù)據(jù)前動(dòng)畫(huà)效果的示例代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02
jquery對(duì)象訪問(wèn)是什么及使用方法介紹
這篇文章主要為大家詳細(xì)介紹了jquery對(duì)象訪問(wèn)是什么及使用方法介紹,感興趣的小伙伴們可以參考一下2016-05-05
jquery如何把參數(shù)列嚴(yán)格轉(zhuǎn)換成數(shù)組實(shí)現(xiàn)思路
某參數(shù)的列只有一個(gè)參數(shù),那么each是失敗,如何保證pp嚴(yán)格是數(shù)組呢,很簡(jiǎn)單var a=[pp];這一句就行了,感興趣的朋友可以參考下哈,希望可以幫助到你2013-04-04
jquery <li>標(biāo)簽 隔若干行加空白或者加虛線的方法
下面小編就為大家?guī)?lái)一篇jquery <li>標(biāo)簽 隔若干行加空白或者加虛線的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12
jQuery代碼實(shí)現(xiàn)圖片墻自動(dòng)+手動(dòng)淡入淡出切換效果
在網(wǎng)頁(yè)上經(jīng)??梢钥吹接斜尘皥D片可以自動(dòng)淡入淡入切換的效果,非常漂亮,實(shí)用性也非常高,今天小編給大家分享基于jquery代碼實(shí)現(xiàn)圖片墻自動(dòng)+手動(dòng)淡入淡出切換效果,感興趣的朋友一起學(xué)習(xí)吧2016-05-05
jquery實(shí)現(xiàn)很酷的網(wǎng)頁(yè)頂部圖標(biāo)下拉菜單效果
這篇文章主要介紹了jquery實(shí)現(xiàn)很酷的網(wǎng)頁(yè)頂部圖標(biāo)下拉菜單效果,效果非常美觀大方,通過(guò)鼠標(biāo)hover事件及頁(yè)面元素的遍歷與樣式操作實(shí)現(xiàn)該功能,需要的朋友可以參考下2015-08-08
JQuery設(shè)置文本框和密碼框得到焦點(diǎn)時(shí)的樣式
設(shè)置文本框和密碼框得到焦點(diǎn)時(shí)的樣式,通過(guò)jquery來(lái)實(shí)現(xiàn),需要注意的是中間用逗號(hào)隔開(kāi),感興趣的朋友可以參考下2013-08-08
再談Jquery Ajax方法傳遞到action(補(bǔ)充)
之前寫(xiě)過(guò)一篇文章Jquery Ajax方法傳值到action,本文是對(duì)該文的補(bǔ)充2014-05-05

