Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,21 @@ Rule.prototype.addChild = function (selector, style) { | |
return this | ||
} | ||
|
||
/** | ||
* Apply rule to an element inline. | ||
* | ||
* @param {Element} element | ||
* @return {Rule} | ||
* @api public | ||
*/ | ||
Rule.prototype.applyTo = function (element) { | ||
for (var prop in this.style) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kof
Author
Member
|
||
element.style[prop] = this.style[prop] | ||
} | ||
|
||
return this | ||
} | ||
|
||
/** | ||
* Converts the rule to css string. | ||
* | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(function () { | ||
var buttons = document.querySelectorAll('button') | ||
|
||
// Apply from stylesheet rule. | ||
var sheet = jss.createStyleSheet(window.styles, true).attach() | ||
sheet.rules.button1.applyTo(buttons[0]) | ||
|
||
// Apply from separate rule. | ||
var button2 = jss.createRule({ | ||
padding: '20px', | ||
background: 'green' | ||
}) | ||
button2.applyTo(buttons[1]) | ||
}()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>applyTo in jss</title> | ||
</head> | ||
<body> | ||
<button>Button 1</button> | ||
<button>Button 2</button> | ||
<script src="../../dist/jss.js"></script> | ||
<script src="./style.js"></script> | ||
<script src="./app.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
window.styles = { | ||
button1: { | ||
padding: '20px', | ||
background: 'blue' | ||
} | ||
} |
@kof I found this: http://stackoverflow.com/questions/21011126/dom-replace-entire-style-attribute-cssstyledeclaration-on-element
Might that help for performance, applying all styles at once for a single render?