博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mootools_MooTools:按媒体设置样式
阅读量:2512 次
发布时间:2019-05-11

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

mootools

I'd bet one of the most used MooTools methods is the setStyle() method, which allows you to set CSS style declarations for an element. One of the limitations of MooTools' setStyle() method is that it sets the specific style for all medias. What if I want to set a style for only a specific media type? I've created a setStile() method that allows you to specify the media for which a style is set.

我敢打赌,最常用的MooTools方法之一是setStyle()方法,该方法可让您设置元素CSS样式声明。 MooTools的setStyle()方法的局限性之一是它为所有媒体设置特定的样式。 如果我只想为特定媒体类型设置样式怎么办? 我创建了一个setStile()方法,该方法允许您指定为其设置样式的媒体。

MooTools JavaScript (The MooTools JavaScript)

Element.implement({	'setStile': function(key,value,media) {		var style = $$('style[media=' + media + ']')[0];		if(!style) {			style = new Element('style',{				'type': 'text/css',				'media': media			});			style.inject(document.head);		}		if(!this.get('id')) {			this.set('id',$uid(this));		}		style.set('text',style.get('text') + '#' + this.get('id') + '{ ' + key + ':' + value + '; }');		return this;	},		'setStiles': function(keyvalhash,media) {		for(var key in keyvalhash) {			this.setStile(key,keyvalhash[key],media);		}		return this;	}});

用法示例 (Example Usages)

$('nonoprint').setStile('color','#f00','print');$('nonoprint').setStile('display','inline','print');$('nonoprint').setStile('border','1px solid #00f','print');$('nonoprint').setStiles({	'background-color': '#fffea1',	'font-weight': 'bold',	'opacity': '.5'},'print');

使用后HTML视图 (The Post-Use HTML View)

Obviously, as you can see from the Post-Use HTML, this isn't an elegant solution but it works in all browsers I tested except Internet Explorer. Hopefully a better solution is presented in the future.

显然,从使用后HTML中可以看出,这不是一个很好的解决方案,但它在除Internet Explorer之外我测试过的所有浏览器中都可以使用。 希望将来会提供更好的解决方案。

翻译自:

mootools

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

你可能感兴趣的文章
Python 网络编程
查看>>
C# EF Code First Migrations数据库迁移
查看>>
将java保存成.xml文件
查看>>
SQl server更新某阶段的匹配关系。
查看>>
go语言练习
查看>>
org.apache.jasper.JasperException: Unable to compile class for JSP
查看>>
centos中的配置文件 分类: B3_LINUX ...
查看>>
1.找两个数下标Two Sum
查看>>
牛客~~wannafly挑战赛19~A 队列
查看>>
MYSQL GTID使用运维介绍(转)
查看>>
5 -- Hibernate的基本用法 --2 2 Hibernate的数据库操作
查看>>
RAID
查看>>
Jquery.Sorttable 桌面拖拽自定义
查看>>
PSP
查看>>
身份证的最准确的正则表达式,绝对让你吃惊啊!
查看>>
14.python读写Excel
查看>>
MySQL备份类别
查看>>
JNI数据类型(转)
查看>>
mysql 主从数据同步
查看>>
ContentType的一些值
查看>>