Jquery Mobile 自定義按鈕圖標(biāo)
很多朋友都反應(yīng)jquery mobile自帶的圖標(biāo)真的是少之又少,另外我也覺得圖標(biāo)偏小(系統(tǒng)自帶的是18*18的),于是琢磨著如何自定義按鈕圖標(biāo),下面小編把我的方法分享給大家。
剛接觸Jquery Mobile框架,遇到個(gè)很現(xiàn)實(shí)問題,就是如何自定義按鈕圖標(biāo),我覺得jquery mobile 自帶的圖標(biāo)實(shí)在是太少了,另外我覺得圖標(biāo)也偏?。ㄏ到y(tǒng)自帶的應(yīng)該是18*18的)下面是我的方法,希望大家踴躍拍磚。
1、第一種方法是比較簡(jiǎn)單的,但是有前提,前提就是你自定義的圖標(biāo)大小應(yīng)該和系統(tǒng)內(nèi)置的保持一致,這樣排版上才不會(huì)出問題,具體方法如下:
首先定義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)的實(shí)現(xiàn)方法,希望大家喜歡。
- jQuery Mobile彈出窗、彈出層知識(shí)匯總
- 使用jQueryMobile實(shí)現(xiàn)滑動(dòng)翻頁效果的方法
- jquery Mobile入門—多頁面切換示例學(xué)習(xí)
- jQuery Mobile開發(fā)中日期插件Mobiscroll使用說明
- jquery mobile動(dòng)態(tài)添加元素之后不能正確渲染解決方法說明
- 讓jQuery Mobile不顯示討厭loading界面的方法
- jquery mobile頁面跳轉(zhuǎn)后樣式丟失js失效的解決方法
- jquery Mobile入門—外部鏈接切換示例代碼
- jquery mobile changepage的三種傳參方法介紹
- jQueryMobile之Helloworld與頁面切換的方法
- jQueryMobile之窗體長(zhǎng)內(nèi)容的缺陷與解決方法實(shí)例分析
相關(guān)文章
jQuery中Chosen三級(jí)聯(lián)動(dòng)功能實(shí)例代碼
Chosen 是一個(gè)JavaScript插件,它能讓丑陋的、很長(zhǎng)的select選擇框變的更好看、更方便,不僅如此,它更擴(kuò)大了,增長(zhǎng)了主動(dòng)篩選的功能。接下來通過本文給大家分享chosen 三級(jí)聯(lián)動(dòng)功能,一起看看吧2017-03-03
jquery之基本選擇器practice(實(shí)例講解)
下面小編就為大家?guī)硪黄猨query之基本選擇器practice(實(shí)例講解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09
jquery使用echarts實(shí)現(xiàn)有向圖可視化功能示例
這篇文章主要介紹了jquery使用echarts實(shí)現(xiàn)有向圖可視化功能,結(jié)合完整實(shí)例形式分析了jquery的echarts.js插件實(shí)現(xiàn)有向圖可視化相關(guān)實(shí)現(xiàn)技巧與操作注意事項(xiàng),需要的朋友可以參考下2019-11-11
jQuery實(shí)現(xiàn)橫向帶緩沖的水平運(yùn)動(dòng)效果(附demo源碼下載)
這篇文章主要介紹了jQuery實(shí)現(xiàn)橫向帶緩沖的水平運(yùn)動(dòng)效果,涉及jQuery中鼠標(biāo)事件及animate方法使用技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-01-01

