js特效:利用SwatchBook建立评论最多的用户的排行榜 – 千丝海阁

首页 » Javascript » js特效:利用SwatchBook建立评论最多的用户的排行榜

js特效:利用SwatchBook建立评论最多的用户的排行榜

5138 31

细心的访客可以看见,首页导航条上,加了个封神榜(topten),这里的封神榜,指将来访的访客按评论总数进行排行,也就是类似读者墙插件读取的用户数的前十位。由于tiandi一直使用最近访客showguests插件,所以一直没有使用读者墙这类插件,今天偶尔看见一个js特效SwatchBook,感觉可以拿来和wordpress的评论者数据结合一下,做出一些排名效果,下图为效果图截图。

名人堂

想看真实效果,请看这里。[flatbtn url=”http://www.tiandiyoyo.com/topten/” size=small type=blue]封神榜示例页面[/flatbtn]

1.打开functions.php文件,插入下面代码以添加showtopten函数,js文件请自行下载获取并调整路径地址。

function showtopten() {
	echo "<script type='text/javascript' src='http://www.tiandiyoyo.com/wp-content/themes/freshblog/javascripts/modernizr.custom.79639.js'></script>";
	global $wpdb;
	$counts = $wpdb->get_results("SELECT COUNT(comment_author) AS cnt, comment_author, comment_author_url, comment_author_email FROM $wpdb->comments where user_id = '0' and comment_approved = 1 GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 10"); 
	echo "<div class='container'>
		<section class='main'>
			<div id='sb-container' class='sb-container'>";
	foreach(array_reverse($counts) as $count){
		$guesturl = $count->comment_author_url;
		$guestavatar = get_avatar($count->comment_author_email, 50);
		$guest = $count->comment_author;
		echo "<div style='transition: all 700ms ease; -webkit-transition: all 700ms ease; -webkit-transform: rotate(0deg);'><span class='sb-icon'><a href=".$guesturl." target=_blank>".$guestavatar."</a><span style='color:#eee'>".$count->cnt."</span></span><h4><span>".$guest."</span></h4></div>";
	}
	echo "<div style='transition: all 700ms ease; -webkit-transition: all 700ms ease; -webkit-transform: rotate(0deg);'><h4><span>名人堂</span></h4><span class='sb-toggle'>都是千年老妖啊</span><h5><span>★千丝海阁</span></h5></div></div><!-- sb-container --></section></div>";

	echo "<script type='text/javascript' src='http://www.tiandiyoyo.com/wp-content/themes/freshblog/javascripts/jquery.swatchbook.js'></script>";

	echo "<script type='text/javascript'>
			$(function() {
			
				$( '#sb-container' ).swatchbook( {
					angleInc : 17,
					neighbor : 15,
					initclosed : true,
					closeIdx : 10
				} );
			
			});
		</script>";    
}

2.打开style.css文件,添加如下样式:

/***************************/
/*     topten css          */
/***************************/
.sb-container {
	position: relative;
	width: 150px;
	height: 400px;
	margin: 30px auto 0 auto;
}

.sb-container div {
    position: absolute;
	top: 0;
	left: 0; 
	width: 130px;
	background: #fff;
	height: 400px;
	border-radius: 5px;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1);
	cursor: pointer;
	text-align: center;
		
	-webkit-transform-origin: 25% 90%;
	-moz-transform-origin: 25% 90%;
	-o-transform-origin: 25% 90%;
	-ms-transform-origin: 25% 90%;
	transform-origin: 25% 90%;
}

.sb-container div:last-child:after{
	content: '';
	position: absolute;
	bottom: 15px;
	left: 15px;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #dddddd;
	background: -moz-linear-gradient(-45deg, #dddddd 0%, #58535e 48%, #889396 100%);
	background: -webkit-gradient(linear, left top, right bottom, color-stop(0%,#dddddd), color-stop(48%,#58535e), color-stop(100%,#889396));
	background: -webkit-linear-gradient(-45deg, #dddddd 0%,#58535e 48%,#889396 100%);
	background: -o-linear-gradient(-45deg, #dddddd 0%,#58535e 48%,#889396 100%);
	background: -ms-linear-gradient(-45deg, #dddddd 0%,#58535e 48%,#889396 100%);
	background: linear-gradient(135deg, #dddddd 0%,#58535e 48%,#889396 100%);
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#dddddd', endColorstr='#889396',GradientType=1 );
	box-shadow: -1px -1px 1px rgba(0,0,0,0.7), 1px 1px 1px rgba(255,255,255,0.1);
}

.sb-container div:nth-child(1){
	background-color: #ea2a29;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 1px 1px 1px rgba(0,0,0,0.1), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(2){
	background-color: #f16729;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 2px 2px 1px rgba(0,0,0,0.1), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(3){
	background-color: #f89322;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 3px 3px 2px rgba(0,0,0,0.2), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(4){
	background-color: #ffcf14;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 4px 4px 4px rgba(0,0,0,0.2), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(5){
	background-color: #ffea0d;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 5px 5px 6px rgba(0,0,0,0.3), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(6){
	background-color: #87b11d;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 6px 6px 8px rgba(0,0,0,0.3), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(7){
	background-color: #008253;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 7px 7px 10px rgba(0,0,0,0.4), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(8){
	background-color: #3277b5;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 8px 8px 12px rgba(0,0,0,0.4), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(9){
	background-color: #4c549f;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 9px 9px 14px rgba(0,0,0,0.4), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:nth-child(10){
	background-color: #764394;
	box-shadow: -1px -1px 3px rgba(0,0,0,0.1), 10px 10px 16px rgba(0,0,0,0.4), inset 0 3px 0 rgba(255, 255, 255, 0.2);
}

.sb-container div:last-child{
	background: #111;
	box-shadow: 
		-1px -1px 3px rgba(0,0,0,0.2),
		12px 12px 20px rgba(0,0,0,0.6),
		inset 2px 2px 0 rgba(255, 255, 255, 0.1);
}

.sb-container div h4{
	color: rgba(255,255,255,0.9);
	text-shadow: 1px 1px 1px rgba(0,0,0,0.2);
	font-weight: 700;
	font-size: 16px;
	text-transform: uppercase;
	border-top: 1px dashed rgba(0,0,0,0.1);
	border-bottom: 1px dashed rgba(0,0,0,0.1);
	margin: 5px;
	padding: 5px;
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	-khtml-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

.sb-container div:last-child h4{
	background: rgba(0,0,0,0.2);
	box-shadow: 0 1px 1px rgba(255,255,255,0.1);
}

.sb-container div:last-child h5{
	font-size: 50px;
	white-space: nowrap;
	text-align: left;
	margin: 0;
	padding: 0;
	position: absolute;
	line-height: 50px;
	top: 0px;
	left: 0px;
	color: #000;
	text-shadow: -1px -1px 1px rgba(255,255,255,0.1);
	text-transform: uppercase;
	
	-webkit-transform: rotate(-90deg) translateX(-157%) translateY(73px);
	-moz-transform: rotate(-90deg) translateX(-157%) translateY(73px);
	-o-transform: rotate(-90deg) translateX(-157%) translateY(73px);
	-ms-transform: rotate(-90deg) translateX(-157%) translateY(73px);
	transform: rotate(-90deg) translateX(-157%) translateY(73px);
	
	-webkit-transform-origin: 0 0;
	-moz-transform-origin: 0 0;
	-o-transform-origin: 0 0;
	-ms-transform-origin: 0 0;
	transform-origin: 0 0;
	
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	-khtml-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

span.sb-icon{
	display: block;
	height: 70px;
	width: 70px;
	margin: 20px auto;
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	-khtml-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

3.新建一个页面模板并命名为topten.php,在模板里相应位置调用showtopten函数,例如:

<?php
/*
Template Name: Topten
*/
?>
<?php get_header(); ?>
<div id="content">
  <div id="innercontent">
    <h2 class="pagetitle">名人堂</h2>
    <div class="entry">
      <?php showtopten(); ?>
    </div>
  <!--end: entry-->
  </div>
</div>
<!--end: content-->
<?php include('sidebar.php'); ?>
<?php get_footer(); ?>

4.最后新建一个页面,启用刚刚创建的topten.php模板。

大功告成啦!来看下实际效果吧:[flatbtn url=”http://www.tiandiyoyo.com/topten/” size=small type=blue]封神榜示例页面[/flatbtn]

文章评分1次,平均分5.0

本文原始地址:https://www.tiandiyoyo.com/2013/07/js-effect-swatchbook-topten/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

    没有相关的文章

评论前先开启评论开关:


31 Comments

  1. 很酷 就是有点卡

载入分页评论...