本代码摘自一国外博客源码.如使用以下代码请谨记做人要厚道,保留Ads by Google字样. 注:网易的新闻频道内容页有相似代码,可以参考.声明:GOOGLE官方不推荐使用,如使用以下代码出现的任何问题本站不负责任.
- 添加新评论
- 阅读次数:
在Javascript中,一切都是对象,包括函数。在Javascript中并没有真正的类,不能像C#,PHP等语言中用 class xxx来定义。但Javascript中提供了一种折中的方案:把对象定义描述为对象的配方(先看一下例子会比较容易理解)。
- 添加新评论
- 阅读次数:
正则表达式:英文、中文、数字、下划线
- 添加新评论
- 阅读次数:
15位和18位身份证的正则表达式及其验证
- 添加新评论
- 阅读次数:
由于marquee是不符合WEB标准的,marquee标签现在用得是越来越少了,所以滚动效果的做法大多也都改用javascript来实现了
- 添加新评论
- 阅读次数:
原文:http://www.rooufer.cn/blog/article.asp?id=131
jQuery实现的滚屏效果实现方法:
一:有上下按钮控制的:
<html>
<head>
<title>jquery滚屏效果</title>
<style type="text/css">
ul,li{margin:0;padding:0}#scrollDiv{width:300px;height:100px;min-height:25px;line-height:25px;border:#ccc 1px solid;overflow:hidden}#scrollDiv li{height:25px;padding-left:10px;}</style>
<script type="text/javascript" src="/js/jquery.js"></script>1:2: <script type="text/javascript">3: (function($){4: $.fn.extend({5: Scroll:function(opt,callback){6: //参数初始化7: if(!opt) var opt={};8: var _btnUp = $("#"+ opt.up);//Shawphy:向上按钮9: var _btnDown = $("#"+ opt.down);//Shawphy:向下按钮10: var timerID;11: var _this=this.eq(0).find("ul:first");12: var lineH=_this.find("li:first").height(), //获取行高13: line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数,默认为一屏,即父容器高度14: speed=opt.speed?parseInt(opt.speed,10):500; //卷动速度,数值越大,速度越慢(毫秒)15: timer=opt.timer //?parseInt(opt.timer,10):3000; //滚动的时间间隔(毫秒)16: if(line==0) line=1;17: var upHeight=0-line*lineH;18: //滚动函数19: var scrollUp=function(){20: _btnUp.unbind("click",scrollUp); //Shawphy:取消向上按钮的函数绑定21: _this.animate({22: marginTop:upHeight23: },speed,function(){24: for(i=1;i<=line;i++){25: _this.find("li:first").appendTo(_this);26: }27: _this.css({marginTop:0});28: _btnUp.bind("click",scrollUp); //Shawphy:绑定向上按钮的点击事件29: });30:31: }32: //Shawphy:向下翻页函数33: var scrollDown=function(){34: _btnDown.unbind("click",scrollDown);35: for(i=1;i<=line;i++){36: _this.find("li:last").show().prependTo(_this);37: }38: _this.css({marginTop:upHeight});39: _this.animate({40: marginTop:041: },speed,function(){42: _btnDown.bind("click",scrollDown);43: });44: }45: //Shawphy:自动播放46: var autoPlay = function(){47: if(timer)timerID = window.setInterval(scrollUp,timer);48: };49: var autoStop = function(){50: if(timer)window.clearInterval(timerID);51: };52: //鼠标事件绑定53: _this.hover(autoStop,autoPlay).mouseout();54: _btnUp.css("cursor","pointer").click( scrollUp ).hover(autoStop,autoPlay);//Shawphy:向上向下鼠标事件绑定55: _btnDown.css("cursor","pointer").click( scrollDown ).hover(autoStop,autoPlay);56:57: }58: })59: })(jQuery);60:61: $(document).ready(function(){62: $("#scrollDiv").Scroll({line:4,speed:500,timer:3000,up:"btn1",down:"btn2"});63: });</script>
</head>
<body>
<p>多行滚动演示:</p>
<div id="scrollDiv">
<ul>
<li>这是公告标题的第一行</li>
<li>这是公告标题的第二行</li>
<li>这是公告标题的第三行</li>
<li>这是公告标题的第四行</li>
<li>这是公告标题的第五行</li>
<li>这是公告标题的第六行</li>
<li>这是公告标题的第七行</li>
<li>这是公告标题的第八行</li>
</ul>
</div>
<button id="btn1">down</button>
<button id="btn2">up</button>
</body>
</html>
二:简洁无控制的
<html>
<head>
<title>多行滚动演示</title>
<style type="text/css">
ul,li{margin:0;padding:0}#scrollDiv{width:300px;height:100px;min-height:25px;line-height:25px;border:#ccc 1px solid;overflow:hidden}#scrollDiv li{height:25px;padding-left:10px;}</style>
<script type="text/javascript" src="/js/jquery.js"></script>1:2: <script type="text/javascript">3: (function($){4: $.fn.extend({5: Scroll:function(opt,callback){6: //参数初始化7: if(!opt) var opt={};8: var _this=this.eq(0).find("ul:first");9: var lineH=_this.find("li:first").height(), //获取行高10: line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数,默认为一屏,即父容器高度11: speed=opt.speed?parseInt(opt.speed,10):500, //卷动速度,数值越大,速度越慢(毫秒)12: timer=opt.timer?parseInt(opt.timer,10):3000; //滚动的时间间隔(毫秒)13: if(line==0) line=1;14: var upHeight=0-line*lineH;15: //滚动函数16: scrollUp=function(){17: _this.animate({18: marginTop:upHeight19: },speed,function(){20: for(i=1;i<=line;i++){21: _this.find("li:first").appendTo(_this);22: }23: _this.css({marginTop:0});24: });25: }26: //鼠标事件绑定27: _this.hover(function(){28: clearInterval(timerID);29: },function(){30: timerID=setInterval("scrollUp()",timer);31: }).mouseout();32: }33: })34: })(jQuery);35:36: $(document).ready(function(){37: $("#scrollDiv").Scroll({line:4,speed:500,timer:3000});38: });</script>
</head>
<body>
<p>多行滚动演示:</p>
<div id="scrollDiv">
<ul>
<li>这是公告标题的第一行</li>
<li>这是公告标题的第二行</li>
<li>这是公告标题的第三行</li>
<li>这是公告标题的第四行</li>
<li>这是公告标题的第五行</li>
<li>这是公告标题的第六行</li>
<li>这是公告标题的第七行</li>
<li>这是公告标题的第八行</li>
</ul>
</div>
</body>
</html>
三:用setInterval函数实现
<ul id="aaa">
<li>这是公告标题的第一行</li>
<li>这是公告标题的第二行</li>
<li>这是公告标题的第三行</li>
<li>这是公告标题的第四行</li>
<li>这是公告标题的第五行</li>
<li>这是公告标题的第六行</li>
<li>这是公告标题的第七行</li>
<li>这是公告标题的第八行</li>
</ul>
<script>1:2:3: setInterval("aaa.appendChild(aaa.firstChild)",500);4:</script>
附注:一个扩展
jQuery.fn.extend({ justUp : function(aSpeed,duration) {this.css({"height":"25px","line-height":"25px"});
this.each(function(){
var _this = this;
var iTimer=0; function scroll(){ iTimer = setInterval(function(){ $(_this).animate({marginTop:"-25px"},aSpeed||500,function(){$(_this).css({marginTop:"0px"}).find("li:first").appendTo(_this);});},duration||3000);
}
scroll();
$(this).hover(function(){this.style.cursor = "pointer";clearInterval(iTimer);},scroll);
});
}
});
水平滚动
// 水平滚动插件(function($){$.fn.extend({ Scroll:function(opt,callback){ //参数初始化if(!opt) var opt={};
var _btnRight = $("#"+ opt.right);//Shawphy:向右按钮
var _btnLeft = $("#"+ opt.left);//Shawphy:向左按钮
var timerID;var _this=this.eq(0).find("ul:first");
var lineW=_this.find("li:first").width(), //获取列表宽度





