博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mootools_MooTools Zebra Tables插件
阅读量:2515 次
发布时间:2019-05-11

本文共 3697 字,大约阅读时间需要 12 分钟。

mootools

Tabular data can oftentimes be boring, but it doesn't need to look that way! With a small MooTools class, I can make tabular data extremely easy to read by implementing "zebra" tables -- tables with alternating row background colors.

表格数据有时可能很无聊,但不必那样看! 使用小型MooTools类,我可以通过实现“斑马”表(具有交替的行背景色的表)来使表格数据非常易于阅读。

CSS (The CSS)

.highlight		{ background:#d5fcdc; }.even			{ background:#fff; }.mo			{ background:#e3f1fb; }.odd			{ background:#eee; }.zebra th		{ padding:5px; background:#ddd; border-bottom:1px solid #999; text-align:left; font-weight:bold; }.zebra td		{ padding:5px 20px 5px 5px; border-bottom:1px solid #ddd; }

The above CSS is extremely basic. I've styled the <TH> tag so that it stands out from table rows. There are four states of rows in my zebra table: highlighted (or "clicked on"), regular even and odd, and a mouseover state -- these are represented by the "even", "mo", "highlight", and "odd" classes. I've added padding and a bottom border to the <TD>'s for presentation.

上面CSS非常基础。 我已经设置了<TH>标记的样式,以使其在表行中脱颖而出。 斑马线表中有四种行状态:突出显示(或“单击”),规则的偶数和奇数以及鼠标悬停状态-这些状态分别由“偶数”,“ mo”,“突出显示”和“奇数”类。 我在<TD>的演示文稿中添加了填充和底部边框。

XHTML (The XHTML)

Award Actor Film
Actor In A Leading Role Daniel Day-Lewis There Will Be Blood
Actress In A Leading Role Marion Cotillard La Vie en Rose
Actor In A Supporting Role Javier Bardem No Country For Old Men
Actress In A Supporting Role Tilda Swinton Michael Clayton
Directing Joel Coen and Ethan Coen No Country For Old Men
Writing Diablo Cody Juno

The above table is a simple, standard table. The only detail of note is that this table is given the "zebra" class, which signals to MooTools that this table should be zebra-ized.

上表是一个简单的标准表。 唯一需要注意的细节是该表被赋予了“斑马”类,该类向MooTools发出信号,该表应该被斑马化。

JavaScript类 (The JavaScript Class)

/* classes */var ZebraTables = new Class({	//initialization	initialize: function(table_class) {		//add table shading		$$('table.' + table_class + ' tr').each(function(el,i) {			//do regular shading			var _class = i % 2 ? 'even' : 'odd'; el.addClass(_class);			//do mouseover			el.addEvent('mouseenter',function() { if(!el.hasClass('highlight')) { el.addClass('mo').removeClass(_class); } });			//do mouseout			el.addEvent('mouseleave',function() { if(!el.hasClass('highlight')) { el.removeClass('mo').addClass(_class); } });			//do click			el.addEvent('click',function() {				//click off				if(el.hasClass('highlight'))				{					el.removeClass('highlight').addClass(_class);				}				//click on				else				{					el.removeClass(_class).removeClass('mo').addClass('highlight');				}			});		});	}});

The class accepts one parameter, which is the class given to tables that should be Zebra-ized. Upon initialization, the class cycles through each table row. During the row looping, the row is given its odd or even CSS class, and a listener is added to the row to highlight the row upon mouseover. The above JavaScript could be placed into an .

该类接受一个参数,这是给应该Zebra化的表的类。 初始化后,该类在每个表行中循环。 在行循环期间,该行被赋予其奇数或偶数CSS类,并且在该行上添加了一个侦听器以在鼠标悬停时突出显示该行。 上面JavaScript可以放在一个 。

JavaScript实现 (The JavaScript Implementation)

/* do it! */window.addEvent('domready', function() {	var zTables = new ZebraTables('zebra');});

To implement ZebraTables, all you need to do is add the above code to any given page.

要实现ZebraTables,您需要做的就是将上述代码添加到任何给定的页面中。

Do you have any suggestions for my zebra tables? Let me know!

您对我的斑马桌有什么建议吗? 让我知道!

翻译自:

mootools

转载地址:http://vppwd.baihongyu.com/

你可能感兴趣的文章
通过镜像下载Android系统源码
查看>>
python字符串格式化 %操作符 {}操作符---总结
查看>>
windows 不能在 本地计算机 启动 Apache
查看>>
iOS开发报duplicate symbols for architecture x86_64错误的问题
查看>>
Chap-6 6.4.2 堆和栈
查看>>
【Java学习笔记之九】java二维数组及其多维数组的内存应用拓展延伸
查看>>
C# MySql 连接
查看>>
sk_buff Structure
查看>>
oracle的级联更新、删除
查看>>
多浏览器开发需要注意的问题之一
查看>>
Maven配置
查看>>
HttpServletRequest /HttpServletResponse
查看>>
SAM4E单片机之旅——24、使用DSP库求向量数量积
查看>>
从远程库克隆库
查看>>
codeforces Unusual Product
查看>>
hdu4348 - To the moon 可持久化线段树 区间修改 离线处理
查看>>
springMVC中一个class中的多个方法
查看>>
cxx signal信号捕获
查看>>
《Android开发艺术探索》读书笔记——Cha3.2.3改变布局参数实现View的滑动
查看>>
python闭包与装饰器
查看>>