jQuery:增强型走马灯公告栏,可以抛弃marquee标签了

1.Html代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div id="container">
    <ul class="noticeList">
        <li><a href="http://www.ihiro.org/wordpress-the-article-automatically-appear-as-two" title="Wordpress:将文章自动显示为两列">Wordpress:将文章自动显示为两列</a></li>
        <li><a href="http://www.ihiro.org/film-2012-really-have-that-day-discovery-channel-expose-for-you" title="电影:《2012》真的有那一天吗?探索频道为你揭露">电影:《2012》真的有那一天吗?探索频道为你揭露</a></li>
        <li><a href="http://www.ihiro.org/information-november-2009-programming-language-list" title="资讯:2009年11月编程语言排行榜">资讯:2009年11月编程语言排行榜</a></li>
        <li><a href="http://www.ihiro.org/a-busy-week-for-rent-a-house-was-finally-gaoding" title="租房:忙碌一周,房子终于搞定">租房:忙碌一周,房子终于搞定</a></li>
        <li><a href="http://www.ihiro.org/my-third-theme-innernews" title="主题:我的第三个主题innerNews提供下载">主题:我的第三个主题innerNews提供下载</a></li>
        <li><a href="http://www.ihiro.org/my-first-plugin-scrolltop" title="插件:我的第一个插件–简约的scrollTop滑动插件">插件:我的第一个插件–简约的scrollTop滑动插件</a></li>
        <li><a href="http://www.ihiro.org/celebrate-my-blog-pr-catapulted-3" title="PageRank:庆贺我的博客PR连升3级">PageRank:庆贺我的博客PR连升3级</a></li>
        <li><a href="http://www.ihiro.org/myeclipse-8-and-registration-number" title="软件:MyEclipse 8.0发布,附注册码">软件:MyEclipse 8.0发布,附注册码</a></li>
        <li><a href="http://www.ihiro.org/tv-leng-jian" title="电视:《冷箭》,让我“失眠”的谍战片">电视:《冷箭》,让我“失眠”的谍战片</a></li>
        <li><a href="http://www.ihiro.org/hd-is-an-attitude" title="下载:高清,是一种态度!">下载:高清,是一种态度!</a></li>
    </ul>
</div>

2.CSS代码:

1
2
3
4
5
6
7
8
* { margin:0; padding:0;}
body { font:12px Verdana, Geneva, sans-serif; color:#666; text-align:center;}
 
#container { width:180px; margin:30px auto; text-align:left; padding:10px; border:1px solid #ccc; height:250px; position:relative; overflow:hidden;}
	.noticeList { width:180px; list-style:inside; position:absolute; top:270px; left:10px;}
	.noticeList li { padding-bottom:5px;}
	.noticeList li a { color:#606060; text-decoration:none;}
	.noticeList li a:hover { color:#09F;}

3.JS代码:(备了部分注释,不懂的可以留言询问。)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
jQuery(function($) {
	function ScrollAction(listObj, listElem, speed, isSeries) {	//listObj为需要滚动的列表,  speed为滚动速度
		var pos, top, aniTop, height;
		var id = '';  //记录setInterval的标记id
 
		pos = listObj.position();	
		top = pos.top;			//列表的top
		aniTop = top;				//记录当前运动时的top
		height = listObj.height();	//列表的高度
 
		var scrollUp = function() {
			aniTop--;
			if(!isSeries) {	//isSeries变量控制是否连续滚动,false不连续,true连续
				if(aniTop == -height) {	//不连续,滚动玩重新滚动
					listObj.css({'top': top});
					aniTop = top;
				};
			} else {
				if(aniTop == -listObj.children().eq(0).height()) {	//连续滚动
					var firstItem = '< ' + listElem +'>' + listObj.children().eq(0).html() + '< /' + listElem +'>';
					listObj.children().eq(0).remove();
					listObj.append(firstItem);
					aniTop = 4;
				};
			};
			listObj.css({'top': aniTop + 'px'});
		};
 
		var hover = function(id) {
			listObj.hover(function() {
				clearInterval(id);
			}, function() {
				id = setInterval(scrollUp, speed);
			});
		};
 
		this.start = function() {
			id = setInterval(scrollUp, speed);
			hover(id);
		};
 
	};
	var sa = new ScrollAction($('.noticeList'), 'li', 30, true);
	sa.start();
});

使用时别忘了引入jQuery库哦,也希望大家给我提出意见,或功能扩充等要求。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
运行环境 操作系统:Windows XP。 Java平台:JDK 1.5。 Web服务器:Tomcat v 5.5.23,下载地址:http://tomcat.apache.org/。 数据库服务器:MySQL v 5.0.45,下载地址:http://www.mysql.com/。 开发平台:Eclipse SDK v 3.2.2,下载地址:http://www.eclipse.org/download/index.jsp。 Eclipse插件TomcatPlugins v 3.2.1,下载地址:http://www.eclipse-plugins.info/eclipse/index.jsp。 Eclipse插件ResourceBundleEditor v 0.7.7,下载地址:http://resourcebundleeditor.com/。 Eclipse插件MyEclipse v 5.5.1,下载地址:http://www.myeclipseide.com/ Spring 采用 2.0 版本 Hibernate 采用3.0版本 ====================================================== 请注意:如出现中文乱码,检查如下配置是否正确。 (1)MySql 数据库是否是utf-8 格式(在安装时选择支持多语言),数据是否正常。 (2)项目是否为utf-8格式(同时看看的源代码文件中,中文是否乱码)。 (3)JSP页面是否是utf-8 格式。 (4)在web.xml 是否配置了编码过滤器。 (5)数据源配置的url(?useUnicode=true&characterEncoding=UTF-8),具体请看项目实例。 如果上面5步都没问题,你就不存在中文乱码问题。 ====================================================== 数据库使用的是MySQL,其版本为5.0.45 版本。 数据库的用户名及密码均为root。 使用的时候,请参考附件数据库导入一节。或将需要用到的某章的数据库目录复制到“mysql安装根目录\data”文件夹下就可以了。 ★★★★★★★★★★★★★★★★★★★★★★★★★ 该实例来源下面这本书 《精通Java EE项目案例-基于Eclipse Spring Struts Hibernate》 本书下载链接,电驴,迅雷皆可 ed2k://|file|%E7%B2%BE%E9%80%9AJava.EE%E9%A1%B9%E7%9B%AE%E6%A1%88%E4%BE%8B-%E5%9F%BA%E4%BA%8EEclipse.Spring.Struts.Hibernate%E5%85%89%E7%9B%98%E6%BA%90%E7%A0%81.rar|70436209|475e7c3548acf955e89e378e760cf894|h=caud4x2auasf3pl2ln27e35fjw2jwxyb|/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值