您当前的位置:首页 > 网站建设笔记 >

dedecms 顶一下点赞功能美化

0

<script type="text/javascript">
//在HTML中嵌入JavaScript代码的方式,定义jQuery.cookie()方法
//也可以使用外部文件来包含jquery的cookie插件jquery.cookie.js
jQuery.cookie = function(name, value, options) {
	if (typeof value != "undefined") {
		options = options || {};
		if (value === null) {
			value = "";
			options.expires = -1;
		}
		var expires = "";
		if (options.expires && (typeof options.expires == "number" || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == "number") {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24*60*60*1000));
			}else{
				date = options.expires;
			}
			expires = "; expires=" + date.toUTCString();
		}
		var path = options.path ? "; path=" + (options.path) : "";
		var domain = options.domain ? "; domain=" + (options.domain) : "";
		var secure = options.secure ? "; secure" : "";
		document.cookie = [name, "=", encodeURIComponent(value), expires, path, domain, secure].join("");
	}else{
		var cookieValue = null;
		if (document.cookie && document.cookie != "") {
			var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
			if(arr != null) {
				cookieValue = decodeURIComponent(arr[2]);
			}
		}
		return cookieValue;
	}
};

function getDigg(aid) {
	var urls = "{dede:global.cfg_phpurl/}/digg_ajax.php?id="+aid;
	$.getJSON(urls+"&jsoncallback=?",function(data){$(".like-button-count").html(data);});
	$(".like-button").click(function() {
		var idCookie = $.cookie(aid);
		if (idCookie) {
			var left = parseInt($(".like-button-count").offset().left)+20, top = parseInt($(".like-button-count").offset().top), obj=$(this);
			$(".zhan").remove();
			$(this).append('<div class="zhan">已赞</div>');
			$(".zhan").css({
				"position":"absolute",
				"z-index":"1",
				"font-size":"14px",
				"color":"black",
				"left":left+"px",
				"top":top+"px"
			}).animate({top:top-30},"slow",function(){$(this).fadeIn("fast").remove();});
		}else{
			var left = parseInt($(".like-button-count").offset().left)+20, top = parseInt($(".like-button-count").offset().top), obj=$(this);
			$(".zhan").remove();
			$(this).append('<div class="zhan">+1</div>');
			$(".zhan").css({
				"position":"absolute",
				"z-index":"1",
				"font-size":"14px",
				"color":"black",
				"left":left+"px",
				"top":top+"px"
			}).animate({top:top-30},"slow",function(){$(this).fadeIn("fast").remove();});
			var urls = "{dede:global.cfg_phpurl/}/digg_ajax.php?action=good&id="+aid;
			$.getJSON(urls+"&jsoncallback=?",function(data){
				var num = parseInt($(".like-button-count").html());
				$(".like-button-count").html(num+1);
				$.cookie(aid,(num+1),{expires:1,path:"/",domain:".wangzhanchengxu.com"});
			});
		}
	});
}
getDigg({dede:field.id/});
</script>

建站咨询

在线咨询真诚为您提供专业解答服务

咨询热线

137 1731 25507×24小时服务热线

微信交流

二维码终于等到你,还好我没放弃
返回顶部