style inline svg - Free Download Change Styles Of Inline SVGs With jQuery SVGLite

Free Download Change Styles Of Inline SVGs With jQuery SVGLite

Posted on

This time I will share jQuery Plugin and tutorial about Change Styles Of Inline SVGs With jQuery SVGLite, hope it will help you in programming stack.

style inline svg - Free Download Change Styles Of Inline SVGs With jQuery SVGLite
File Size: 101 KB
Views Total: 301
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

SVGLite is a tiny SVG manipulation jQuery plugin that dynamically changes the fill or stroke properties of an SVG image and makes it fully responsive regardless of how you resize the viewport.

How to use it:

1. Insert the SVGLite plugin after jQuery library.

1 <script src="/path/to/cdn/jquery.min.js"></script>
2 <script src="/path/to/svglite-min.js"></script>

2. Embed an SVG into the page.

1 <svg id="example" ...>
2   Paths Here
3 </svg>

3. Initialize the plugin on the SVG element and we’re ready to go.

1 $('#example').svglite({
2   // options here
3 });

4. Change the styles of your SVG element by adding or replacing CSS classes.

01 // replace all classes
02 $('#path_id').pathclass('yourClass');
03  
04 // add a CSS class
05 $('#path_id').pathclass('yourClass','add');
06  
07 // clear all CSS classes
08 $('#path_id').pathclass();
09  
10 // remove a specific CSS class
11 $('#path_id').pathclass('yourClass','remove');

5. Add patterns to SVG paths.

01 // replace all classes
02 $('#path_id').pathclass_pattern('yourClass');
03  
04 // add a CSS class
05 $('#path_id').pathclass_pattern('yourClass','add');
06  
07 // clear all CSS classes
08 $('#path_id').pathclass_pattern();
09  
10 // remove a specific CSS class
11 $('#path_id').pathclass_pattern('yourClass','remove');
1 <defs>
2   <pattern id='yourPattern' width="1" height="1.3" viewBox="0 0 100 100" preserveAspectRatio="xMaxYMax slice">
3     <image xlink:href='bg.jpg' width="100" height="100" preserveAspectRatio="none"></image>
4   </pattern>
5 </defs>
1 #example path.yourClass {
2   fill: url(#yourPattern);
3 }

6. All default configuration options.

01 $('#example').svglite({
02  
03   // resize the SVG on window resize
04   resize: false,
05  
06   // specific size you want the SVG to be sized to
07   special: '',
08  
09   // set the animation timing for the patterns
10   speed: 1500,
11  
12   // default opacity
13   default_opacity: 1,
14  
15   // path opacity you're changing to
16   change_opacity: 1,
17  
18 });

7. Global settings.

1 // for 'special' config
2 svglitedefs.resize['jqueryscript'] = 600;
3 $('#svg').svglite({special:'jqueryscript'});
4  
5 // set a maximum width
6 svglitedefs.max(1024);

This awesome jQuery plugin is developed by kaitwalla. For more Advanced Usages, please check the demo page or visit the official website.