帶動畫特效的點贊+1
這是html的程式碼 特效的js見附錄 需要jQuery的支援
<div class="mui-media-body ">
<span onclick="to_reply_list('${obj.id}')" style="float: left; "><img src="${contextPath}/resources/dataTreasure/images/hongzan.png " style="zoom: 35% "/> </span>
<span onclick="to_reply_list('${obj.id}')" style="float: left; margin-top: 3%;font-size: 20px; color: red; "><span id="zan_number${obj.id}">${obj.number}</span>人覺得很贊</span>
<span onclick="to_comment('${obj.id}')" style="float: right; padding-left: 10%; padding-top: 1%; "><img src="${contextPath}/resources/dataTreasure/images/pinglun.png " style="zoom: 35% " /></span>
<span onclick="zan('${obj.id}')" style="float:right; " id="btn${obj.id}"><img src="${contextPath}/resources/dataTreasure/images/zan.png " style="zoom: 35% "/></span>
<span>btn${obj.id}</span>
</div>
複製下邊的js寫到單獨的js檔案裡邊 部落格無法上傳附件
(function($) {
$.extend({
tipsBox: function(options) {
options = $.extend({
obj: null, //jq物件,要在那個html標籤上顯示
str: "+1", //字串,要顯示的內容;也可以傳一段html,如: "<b style='font-family:Microsoft YaHei;'>+1</b>"
startSize: "12px", //動畫開始的文字大小
endSize: "30px", //動畫結束的文字大小
interval: 600, //動畫時間間隔
color: "red", //文字顏色
callback: function() {} //回撥函式
}, options);
$("body").append("<span class='num'>" + options.str + "</span>");
var box = $(".num");
var left = options.obj.offset().left + options.obj.width() / 2;
var top = options.obj.offset().top - options.obj.height();
box.css({
"position": "absolute",
"left": left + "px",
"top": top + "px",
"z-index": 9999,
"font-size": options.startSize,
"line-height": options.endSize,
"color": options.color
});
box.animate({
"font-size": options.endSize,
"opacity": "0",
"top": top - parseInt(options.endSize) + "px"
}, options.interval, function() {
box.remove();
options.callback();
});
}
});
})(jQuery);
/*$(function() {
$("#btn").click(function() {
$.tipsBox({
obj: $(this),
str: "贊+1",
callback: function() {
//alert(5);
}
});
});
});
*/
//更具邏輯更改下邊的方法 其他的不用動
function zan(v_id){
alert(v_id)
//非同步查詢這個使用者有沒有 點過贊
var url="/weixin/handle_zambia"
$.ajax({
url:url,
type:'post',
data:{
v_id:v_id
},success:function(data){
alert('來了')
var btn = '#btn'+v_id;
alert(btn)
if(data==0){
$.tipsBox({
obj: $(btn),
str: "贊+1",
callback: function() {
}
});
$.ajax({
url:'/weixin/zan_number',
type:'post',
data:{
v_id:v_id
},success:function(data){
var zan_number = '#zan_number'+v_id;
alert(zan_number)
alert(data+"范德薩范德薩發生的的")
$(zan_number).html(data);
}
});
}
if(data==1){
alert('你已經贊過這篇文章')
}
}
});
}