get set keep ratio - Download Get/Set/Keep The Ratio Aspect Of An Element - jQuery KeepRatio

Download Get/Set/Keep The Ratio Aspect Of An Element – jQuery KeepRatio

Posted on

This time I will share jQuery Plugin and tutorial about Get/Set/Keep The Ratio Aspect Of An Element – jQuery KeepRatio, hope it will help you in programming stack.

get set keep ratio - Download Get/Set/Keep The Ratio Aspect Of An Element - jQuery KeepRatio
File Size: 3.97 KB
Views Total: 269
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

The jQuery KeepRatio library provides 3 methods to set, get, and keep the aspect ratio of a DOM element.

Great for responsive design that keeps your element with the same aspect ratio on different screens.

How to use it:

1. Insert the JavaScript file keep-ratio.js after jQuery.

2         integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
3         crossorigin="anonymous">
4 </script>
5 <script src="js/keep-ratio.js"></script>

2. Set the aspect ratio.

1 <div class="box">
2   ... content ...
3 </div>
1 var $els = $( ".box" );
2  
3 // 1:1
4 $els.ratio( 1 );

3. Keep the current aspect ratio.

1 var $els = $( ".box" );
2 $els.keepRatio();

4. Outpu the aspect ratio in the console.

1 var $els = $( ".box" );
2 console.log( "keepRatio", $els );

5. Restore the aspect ratio.

1 $els.freeRatio( true )

6. You can also set the aspect ratio in the data attribute:

1 <div class="box"
2      data-keep-ratio=1>
3 </div>
1 $.keepRatio.register()

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

source : jquery.net