leaderkmfk.blogg.se

Css for js
Css for js




NgCss is an Angular Module+Filter+Factory (aka: plugin) that supports Angular 1.2+ (so back to IE8)īoth of these tool sets allow you to do this in a STYLE tag or within an external *.css file: /*Īnd this in your on-page style attributes: blah I ran into a similar problem and have developed two standalone tools to accomplish this:ĬjsSS.js is a Vanilla Javascript tool (so no external dependencies) that supports back to IE6. Once again, though, this is merely an off-the-top-of-the-head example harnessing the power of dynamic CSS via server-side scripting can lead to some pretty incredible stuff.

css for js

Another case would be doing something like allowing the user to create a custom theme, storing it in a database, and then using PHP to set various properties, like so: This is only one example of dynamic CSS there are virtually limitless possibilities when combining CSS and server-side code. This would set the background image to whatever was stored in the $user_country variable. For example (and I absolutely love doing things like this):

css for js

If this is the case, you can use a server-side scripting language to do so. To facilitate potentially solving your problem given the information you've provided, I'm going to assume you're seeking dynamic CSS. By using something like body, it will execute immediately on page load.

css for js

In both techniques, the code doesn't execute unless the CSS selector matches an element within the document. The HTC file executes the main() function on the event ondocumentready (referring to the HTC document's readiness.) XBL with Firefoxįirefox supports a similar XML-script-executing hack, using XBL.Īll of the code within the constructor tag will be executed (a good idea to wrap code in a CDATA section.) HTC with IEĪnd within that script.htc file have something like: These techniques don't exectue JavaScript from CSS directly, but the effect is the same. A similar technique for Firefox exists, using XBL. As Paolo mentions, one way in IE is the expression technique, but there's also the more obscure HTC behavior, in which a seperate XML that contains your script is loaded via CSS. IE and Firefox both contain ways to execute JavaScript from CSS.






Css for js