This time I will share jQuery Plugin and tutorial about jQuery Based Viewport Size And isTouch Checker – viewportInfo, hope it will help you in programming stack.
viewportInfo is a jQuery plugin that detects the current viewport size (Desktop, Mobile, Tablet) and checks if the current device is touchable.
How to use it:
1. Load the JavaScript file viewportInfo.js
after jQuery library and the viewportInfo is read for use.
1 |
< script src = "//code.jquery.com/jquery-3.2.1.slim.min.js" ></ script > |
2 |
< script src = "viewportInfo.js" ></ script > |
2. Create the html elements to display the results.
1 |
< div id = "viewport-size" >Viewport Size: < span class = "label" ></ span ></ div > |
2 |
< div id = "touch-info" >Touch Enabled: < span class = "label" ></ span ></ div > |
3. Initialize the plugin and set the screen resolutions as follow.
4. The plugin provides a callback function which will be fired on viewport change.
07 |
}).onChange( function (viewport,isTouch){ |
08 |
$( '#viewport-size .label' ).text(viewport); |
09 |
$( '#touch-info .label' ).text(isTouch); |
This awesome jQuery plugin is developed by faraazmalak. For more Advanced Usages, please check the demo page or visit the official website.