wordpress 评论滑动显示

方法来自于:http://loosky.net/?p=1871

1、将下面的JS代码存为comment-slider.js,放入你的博客主题目录下:

function H$(i) {return document.getElementById(i)}
function H$$(c, p) {return p.getElementsByTagName(c)}
var slider = function () {
	function init (o) {
		this.id = o.id;
		this.at = o.auto ? o.auto : 3;
		this.o = 0;
		this.pos();
	}
	init.prototype = {
		pos : function () {
			clearInterval(this.__b);
			this.o = 0;
			var el = H$(this.id), li = H$$('li', el), l = li.length;
			var _t = li[l-1].offsetHeight;
			var cl = li[l-1].cloneNode(true);
			cl.style.opacity = 0; cl.style.filter = 'alpha(opacity=0)';
			el.insertBefore(cl, el.firstChild);
			el.style.top = -_t + 'px';
			this.anim();
		},
		anim : function () {
			var _this = this;
			this.__a = setInterval(function(){_this.animH()}, 20);
		},
		animH : function () {
			var _t = parseInt(H$(this.id).style.top), _this = this;
			if (_t >= -1) {
				clearInterval(this.__a);
				H$(this.id).style.top = 0;
				var list = H$$('li',H$(this.id));
				H$(this.id).removeChild(list[list.length-1]);
				this.__c = setInterval(function(){_this.animO()}, 20);
				//this.auto();
			}else {
				var __t = Math.abs(_t) - Math.ceil(Math.abs(_t)*.07);
				H$(this.id).style.top = -__t + 'px';
			}
		},
		animO : function () {
			this.o += 2;
			if (this.o == 100) {
				clearInterval(this.__c);
				H$$('li',H$(this.id))[0].style.opacity = 1;
				H$$('li',H$(this.id))[0].style.filter = 'alpha(opacity=100)';
				this.auto();
			}else {
				H$$('li',H$(this.id))[0].style.opacity = this.o/100;
				H$$('li',H$(this.id))[0].style.filter = 'alpha(opacity='+this.o+')';
			}
		},
		auto : function () {
			var _this = this;
			this.__b = setInterval(function(){_this.pos()}, this.at*1000);
		}
	}
	return init;
}();

2、将如下CSS内容复制到你的主题的style.css中(借鉴了LiveME的,大家根据需要进行必要的修改):

.avatar-photo{width:30px;height:30px;}
.home-talking{width:635px;float:left;margin:16px 0 10px 5px;}
.say-also,#home-start-more{font-size:12px;font-weight:400;font-family:Tahoma, Arial, sans-serif;float:right;padding-right:8px;}
.home-comment-slider{position:relative;float:left;width:640px;height:270px;overflow:hidden;margin:-5px 0 0 -2px;}
.home-comment-slider ul li{list-style:none;}
.home-slider{width:1000px;position:absolute;padding:0 20px;}
.home-slider li{font-size:13px;margin-left:-7px;border-bottom:thin dotted #D0D0D0;overflow:hidden;line-height:17px;padding:5px 0;}
.home-slider li:hover{background:#F3F3EA;}

在相应的位置添加如下代码(可以是页面或者侧边栏等),要注意你的js代码存放的位置,我的是放在主题下面的JS目录下:

		<div class="home-talking">
           <h2>他们正在说……<a class="say-also" href="#respond">| 我也想说»</a>
        </h2></div>
        <script type="text/javascript"src="http://js.014.cc/simple/slider.js"></script>
        <div class="home-comment-slider">
            <ul id="slider" class="home-slider">
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, comment_content AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND comment_author_email != '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 6";
$comments = $wpdb->get_results($sql);
foreach ($comments as $comment) {
$a= 'http://014.cc/avatar/'.md5(strtolower($comment->comment_author_email)).'.jpg';
$output .= "\n<li><img src='". $a ."' alt='Gravatar' title='".$comment->comment_author."' class='avatar-photo' /><a href=\"" . htmlspecialchars(get_comment_link( $comment->comment_ID )) . "\" title=\"on " .$comment->post_title . "\">".$comment->com_excerpt."</a><br/></li>";
}
$output = convert_smilies($output);
echo $output;
?>
            </ul>
            <div class="home-bottomcover"></div>
        </div>
		<script type="text/javascript">new slider({id:'slider'})</script>

发表评论

电子邮件地址不会被公开。

 smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles smiles

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

无觅相关文章插件,快速提升流量