(function($,window,undefined){ jQuery.fx.interval=30; $.fn.comments=function(delay){ var requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(/* function */ callback, /* DOMElement */ element){ window.setTimeout(callback, 1000 / 60); }; })(); $(this).find("li").css({"margin-bottom":"0px","padding":"0px"}); $(this).find("li *").css({"padding-left":"5px"}); $(this).each(function(){ if(!delay) delay=15; var timer=null; var timer2=null; var that=$(this).find("ul"); that.find("li").each(function(){ this.initialHeight=this.offsetHeight+20; }); var fadeoutFirst=function(){ var li=$(that).find("li").last(); var first=$(that).find("li").first(); li.clearQueue(); li.fadeTo(1,1,function(){ var ele=li[0]; var height=ele.initialHeight; //take off the padding of the box li.clearQueue(); var parent=ele.parentNode; parent.removeChild(ele); parent.insertBefore(ele,first[0]); li.clearQueue(); li[0].style.height="0px"; li.animate({height:height+"px"},7000, 'linear',function(){ li.css({height:height+"px"}); }); }); timer=setTimeout(function(){fadeoutFirst();},delay); } var comments=$(this); var target=0; var over=false; $(this).bind({ mousemove:function(e){ over=true; clearTimeout(timer2); clearTimeout(timer); target=(e.clientY*2-300)/this.offsetHeight*(comments[0].scrollHeight-comments[0].offsetHeight) }, mouseout:function(){ over=false; clearTimeout(timer2); timer2=setTimeout(function(){ if(timer) clearTimeout(timer); timer=setTimeout(function(){fadeoutFirst();},delay); target=0; },700); } }); $(this).find("li").bind("mouseover",function(){ $(this).css({backgroundColor: "#222"}); }); $(this).find("li").bind("mouseout",function(){ $(this).css({backgroundColor: "#111"}); }); timer=setTimeout(function(){fadeoutFirst();},delay); var container=this; var autoscroll=function(){ if(comments[0].scrollTop!=target){ comments[0].scrollTop-=(((comments[0].scrollTop-target)/50)|0)+1; } requestAnimFrame(autoscroll,container); } autoscroll(); //requestAnimFrame(autoscroll,container); }); } })(jQuery,window); $(function(){ $('#comments').comments(7000); });