Show:

StyleSheet Class

Module: stylesheet

动态修改外部或内联样式表

Constructor

StyleSheet

(
  • config
)

Parameters:

Example:

require(['node', 'stylesheet'], function( $, StyleSheet){
    var linkStyleSheet = new StyleSheet('#linkcss');
    $('#change-link-css').on('click', function(ev){
        linkStyleSheet.set('.link',{
            color : 'red'
        });
    });

    var innerStyleSheet = new StyleSheet('#my-style');
    $('#change-style-css').on('click', function(ev){
        innerStyleSheet.set('.style p',{
            color : 'red'
        });
    });
    $('#get-p-styletext').on('click', function(ev){
        alert(innerStyleSheet.get('.style'));
    });
});
  • Index
  • Methods
  • Properties
  • Attributes

Item Index

Properties

Attributes

Methods

disable

()

禁用当前 stylesheet 所在样式表的所有样式

Returns:

当前实例

enable

()

启用当前 stylesheet 所在样式表的所有样式

Returns:

当前实例

get

(
  • selectorText
)
String

获取对应 selectorText 的样式定义文本.

Parameters:

  • selectorText String

    选择器字符串

Returns:

Example:

` require(['stylesheet'],function(StyleSheet){ // use stylesheet a { color:red; }

var stylesheet = new StyleSheet({
    el: '#existing'
});

stylesheet.get('a'); // => color:red

});

isEnabled

() Boolean

当前样式表是否已经被启用

Returns:

set

(
  • selectorText
  • css
)

设置对应 selectorText 的样式定义

Parameters:

  • selectorText String

    选择器字符串

  • css Object

    样式键值对

Returns:

当前实例

Example:

` require(['stylesheet'],function(StyleSheet){ // use stylesheet a { color:red; }

var stylesheet = new StyleSheet({
    el: '#existing'
});

stylesheet.set('a',{
    color:'',
    fontSize:'18px'
}).get('a'); // => font-size:18px;

});

Properties

el

HTMLElement

link 元素节点

Attributes

el

HTMLElement | String

link 节点或选择器