javascript - Insert Multiple CSS rules into a stylesheet -
okay, need add rules style sheet, needs cross browser, need multiple rules.
now can 1 working (chrome) singular line.
however, can't find documentation or related multiple lines.
the idea add multiple css animations using browser prefixes well, add fun.
this trying (i'm debugging in chrome):
stylesheet.insertrule("@-webkit-keyframes userscore { 0% { width: 0px; } 100% {width: " + (monkeyscore * 20) + "px;} }", stylesheet.cssrules.length); stylesheet.insertrule("@-moz-keyframes userscore { 0% { width: 0px; } 100% {width: " + (monkeyscore * 20) + "px;} }", stylesheet.cssrules.length); stylesheet.insertrule("@-ms-keyframes userscore { 0% { width: 0px; } 100% {width: " + (monkeyscore * 20) + "px;} }", stylesheet.cssrules.length); stylesheet.insertrule("@keyframes userscore { 0% { width: 0px; } 100% {width: " + (monkeyscore * 20) + "px;} }", stylesheet.cssrules.length); and after need add browser prefix each animation:
document.getelementbyid('starscoloured').style.webkitanimationname = "userscore"; document.getelementbyid('starscoloured').style.mozanimationname = "userscore"; document.getelementbyid('starscoloured').style.msanimationname = "userscore"; document.getelementbyid('starscoloured').style.animationname = "userscore"; and doesn't work, i'm not surprised, don't know actual way add more one. when try , add prefixed animationname element.
i've tried put rules 1 line, so:
stylesheet.insertrule("@-webkit-keyframes userscore { 0% { width: 0px; } 100% {width: " + (monkeyscore * 20) + "px;} } @-moz-keyframes userscore { 0% { width: 0px; } 100% {width: " + (monkeyscore * 20) + "px;} } @-ms-keyframes userscore { 0% { width: 0px; } 100% {width: " + (monkeyscore * 20) + "px;} } @keyframes userscore { 0% { width: 0px; } 100% {width: " + (monkeyscore * 20) + "px;} }", stylesheet.cssrules.length); again no luck, gives me error of:
uncaught syntaxerror: failed execute 'insertrule' on 'cssstylesheet': failed parse rule '@-webkit-keyframes userscore { 0% { width: 0px; } 100% {width: 380px;} } @-moz-keyframes userscore { 0% { width: 0px; } 100% {width: 380px;} } @-ms-keyframes userscore { 0% { width: 0px; } 100% {width: 380px;} } @keyframes userscore { 0% { width: 0px; } 100% {width: 380px;} }'. if try them separate rule, error of: uncaught syntaxerror: failed execute 'insertrule' on 'cssstylesheet': failed parse rule '@-moz-keyframes userscore { 0% { width: 0px; } 100% {width: 380px;} }'.
i try in firefox, , following error, relating first insertrule line (chromes):
syntaxerror: invalid or illegal string specified so that's it.
any appreciated!
i trying avoid jquery if can it.
and i'm sure documentation on multiple lines me , others.
thanks in advance
how modifying <style> tag?
<style id="custom-styles"></style> <script> var red = '#f00'; document.getelementbyid('custom-styles').innerhtml = 'body { color: ' + red + '; }'; </script> here's small demo: http://jsbin.com/mamekame/2/edit?html,js,output
Comments
Post a Comment