Light source for CSS3 shadows
Light source class provides a way to define light source position and emulate text and box shadows according to provided position of light source. It is also possible to toggle light source.
Right now this effect is unsupported in IE all versions.
Contents
Download
Example codes
<!DOCTYPE html> <html> <head> <style type='text/css'> #simple { width: 300px; position: absolute; top: 100px; left: 100px; } .sub { margin: 50px; border: 1px solid black; } #source { position: absolute; top: 190px; left: 200px; } </style> </head> <body> <div id='simple'> <div class='sub'>I am a text one</div> <div class='sub'>I am a text two</div> </div> <div id='source'> LighSource here </div> <script type="text/javascript" src="./light_source.packed.js" ></script> <script type="text/javascript"> var ls = new light_source("simple",{ //height of light source above objects sourceHeight: 3, //blur level against distance maxBlur: 50, //color of shadow shadowColor: "#aaa", //aplly shadow to text textShadow: true, //apply shadow to box boxShadow: true, //apply effect to all element's children includeChild: true, //x position of light source sourceX: 230, //y position of light source sourceY: 190 }); </script> </body> </html>
Live Examples
Examples in action
Method list
Constructor
| Method name | new light_source(id, config); |
| Description | Provide light source position for HTML elements |
| Input parameters | string or HTML element id - id of element or HTML element itself, where to add blur effect effect
|
| Example input | var ls = new light_source("example",{
//height of light source above objects
sourceHeight: 3,
//blur level against distance
maxBlur: 50,
//color of shadow
shadowColor: "#aaa",
//aplly shadow to text
textShadow: true,
//apply shadow to box
boxShadow: true,
//apply effect to all element's children
includeChild: true,
//x position of light source
sourceX: 230,
//y position of light source
sourceY: 190
}); |
Change light source position
| Method name | setSource(x,y) |
| Description | Change position of light source |
| Input parameters | int x - x position of light source int y - y position of light source |
| Example | ls.setSource(100,100) |
Turn light source off
| Method name | off() |
| Description | Turn the light source off |
| Example | ls.off() |
Turn light source on
| Method name | on() |
| Description | Turn the light source on using last known position |
| Example | ls.on() |
Latest changes
None for nowYou may also be interested in:
Powered by BlogAlike.com










