javascript實(shí)現(xiàn)手動(dòng)點(diǎn)贊效果的方法

這篇文章將為大家詳細(xì)講解有關(guān)javascript實(shí)現(xiàn)手動(dòng)點(diǎn)贊效果的方法,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了翁牛特免費(fèi)建站歡迎大家使用!

做移動(dòng)開發(fā)的時(shí)候經(jīng)常會(huì)遇到點(diǎn)贊的一些處理,尤其是當(dāng)使用字體圖標(biāo)的時(shí)候,由于僅希望改變字體,但是字體經(jīng)過(guò)編譯之后又和它的.html()不一致,所以導(dǎo)致判斷起來(lái)比較麻煩,最后想了一個(gè)辦法來(lái)解決此問(wèn)題。

還有一種點(diǎn)贊是點(diǎn)贊之后后面跟有數(shù)字,點(diǎn)擊之后顏色變化并且數(shù)字+1,當(dāng)再次點(diǎn)擊的時(shí)候,顏色改變并且數(shù)字-1。

以下是我寫的一個(gè)小例子來(lái)簡(jiǎn)單實(shí)現(xiàn)。

效果圖如下:

 javascript實(shí)現(xiàn)手動(dòng)點(diǎn)贊效果的方法

HTML代碼:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>點(diǎn)贊</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
 <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<link rel="stylesheet" type="text/css" href="css/style.css" >
<script src="js/Zepto.js"></script>
<script src="js/touch.js"></script>
</head>
<body>
<div class="method1">
 <p>
 <i class="iconfont icon">&#xe600;</i><a class="iconfont"  id="node">&#xe600;</a> 
 </p>
 <p>
 <i class="iconfont icon">&#xe600;</i>
 </p>
 <p>
 <i class="iconfont icon">&#xe600;</i>
 </p>
</div> 
<div class="method2">
 <p>
 <i class="iconfont icon">&#xe602;</i><span>50</span>
 </p>
 <p>
 <i class="iconfont icon">&#xe602;</i><span>60</span>
 </p>
 <p>
 <i class="iconfont icon">&#xe602;</i><span>80</span>
 </p>
</div> 
<script src="js/jss.js"></script>
</body>
</html>

css代碼:

@font-face {font-family: 'iconfont';
 src: url('iconfont.eot'); /* IE9*/
 src: url('iconfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
 url('iconfont.woff') format('woff'), /* chrome、firefox */
 url('iconfont.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
 url('iconfont.svg#iconfont') format('svg'); /* iOS 4.1- */
}
.iconfont{
 font-family:"iconfont" !important;
 font-size:16px;font-style:normal;
 -webkit-font-smoothing: antialiased;
 -webkit-text-stroke-width: 0.2px;
 -moz-osx-font-smoothing: grayscale;}
*{
 margin: 0;
 padding: 0;
}
.method1 {
 color: green;
}
.method1 p,.method2 p {
 padding-left: 20px;
 margin-top: 10px;
}
.icon {
 cursor: pointer;
 font-size: 30px;
}
.method2 {
 color: #000;
}
.method2 span {
 font-size: 30px;
}

js代碼:

var str = $("#node").html();
$(".method1").on("tap","i",function(){
 var html = $(this).html();
 if(html == str){
 $(this).html("&#xe601;");
 }else{
 $(this).html("&#xe600;");
 }
});
$(".method2").on("tap","p",function(){
 var color = $(this).find("i").css("color");
 var number = $(this).find("span").html();
 if(color == "rgb(0, 0, 0)"){
 $(this).find("i").css("color","#f00");
 $(this).find("span").html(number*1+1);
 }else if(color == "rgb(255, 0, 0)"){
 $(this).find("i").css("color","#000");
 $(this).find("span").html(number*1-1);
 }
})

關(guān)于“javascript實(shí)現(xiàn)手動(dòng)點(diǎn)贊效果的方法”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

本文標(biāo)題:javascript實(shí)現(xiàn)手動(dòng)點(diǎn)贊效果的方法
網(wǎng)頁(yè)地址:http://www.muchs.cn/article4/geeeie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、電子商務(wù)、面包屑導(dǎo)航、Google、營(yíng)銷型網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)