本文实例讲述了jQuery+ajax实现文章点赞功能的方法。分享给大家供大家参考,具体如下:
前几日有童鞋问我索要本站右上角的点赞功能,麦葱左思右想,决定把这功能分享出来,希望此功能对各位会带来方便哦。
代码很简单,jQuery+php实现的。
jQuery代码:
jQuery(document).ready(function($) { $(".zan").click(function(e){ var $i=$(".zan i"), $b=$("<b>").text("+1"), n=parseInt($i.text()); $b.css({ "bottom":0, "z-index":999, }); $i.text(n+1); $(".zan").append($b); $b.animate({"bottom":100,"opacity":0},1000,function(){$b.remove();}); var d = setInterval(function(){ clearInterval(d); if($(".zan b").length == 1){ $.post("",{zan:$i.text()}) } },1000) e.stopPropagation(); }); });
php代码:
<"zan.txt"; if(isset($_POST['zan'])){ $num = (int)$_POST['zan']; $save = fopen($path,"w"); fwrite($save,$num); fclose($save); echo "good"; exit(); $zan = file_exists($path) "htmlcode"><div class="main"> <div class="zan"><em>看官们给了 <i><"htmlcode">.main { position: relative; font-size: 10pt; line-height: 18px; margin: 40px auto; width: 800px; height: 170px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none;} .zan { position: absolute; top: 20%; left: 45%; width: 160px; height: 110px; background: url("zan.jpg") center no-repeat; cursor: pointer; opacity: 0.85; } .zan:active { opacity: 1; } .zan em { position: absolute; color: #333; font-style: normal; bottom: -15px; width: 100%; text-align: center; } .zan i { font-style: normal; color: #E94F06; } .zan b { position: absolute; color: #E94F06; font-style: normal; bottom: -15px; width: 100%; text-align: center; }就是这样,简单吧!
下面是完整代码:
<"zan.txt"; if(isset($_POST['zan'])){ $num = (int)$_POST['zan']; $save = fopen($path,"w"); fwrite($save,$num); fclose($save); echo "good"; exit(); } $zan = file_exists($path) "utf-8"> <title>我要点赞</title> <style> .main { position: relative; font-size: 10pt; line-height: 18px; margin: 40px auto; width: 800px; height: 170px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none;} .zan { position: absolute; top: 20%; left: 45%; width: 160px; height: 110px; background: url("zan.jpg") center no-repeat; cursor: pointer; opacity: 0.85; } .zan:active { opacity: 1; } .zan em { position: absolute; color: #333; font-style: normal; bottom: -15px; width: 100%; text-align: center; } .zan i { font-style: normal; color: #E94F06; } .zan b { position: absolute; color: #E94F06; font-style: normal; bottom: -15px; width: 100%; text-align: center; } </style> </head> <body> <div class="main"> <div class="zan"><em>看官们给了 <i><"jquery.min.js"></script> <script> jQuery(document).ready(function($) { $(".zan").click(function(e){ var $i=$(".zan i"), $b=$("<b>").text("+1"), n=parseInt($i.text()); $b.css({ "bottom":0, "z-index":999, }); $i.text(n+1); $(".zan").append($b); $b.animate({"bottom":100,"opacity":0},1000,function(){$b.remove();}); var d = setInterval(function(){ clearInterval(d); if($(".zan b").length == 1){ $.post("",{zan:$i.text()}) } },1000) e.stopPropagation(); }); }); </script> </body> </html>标题都说了是无上限点赞的,So,麦葱告诉大家个小诀窍:
/* 怒赞 */ jQuery.noConflict(); function zan() { setInterval(function () { jQuery(".zan").click(); zan(); }, 600) } zan();当然,如果你使用了加速乐防CC(麦葱就是),怒赞请求量过多,会被屏蔽掉哦!除非你取消掉jQuery里的POST
希望本文所述对大家jQuery程序设计有所帮助。
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 群星.2022-传家电视剧原声带【东阳欢娱】【FLAC分轨】
- 《摇滚教父 伍佰黄金精选 2CD》 [WAV+CUE][1GB]
- 《凤凰传奇 我从草原来》[WAV/分轨][400MB]
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】
- 林忆莲.2019-0(2023精装版)【环球】【WAV+CUE】
- Supper.Moment.2016-The.Moment【寰亚】【FLAC分轨】
- 范莉丝.1979-送郎一朵牵牛花(LP版)【大联机构】【WAV+CUE】