InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

jQuery tutorials

    jQuery Ajax

    • jQuery JSONP
    • jQuery .post()
    • jQuery .load()
    • load script with cache enabled
    • jQuery .ajax() file upload

    jQuery CSS

    • change table cells color based on value
    • check if element is visible in viewport
    • display auto fade out message
    • fitvids.js for automatically resizing videos
    • get class list of an element
    • jQuery toggleClass() examples
    • make a div stick at top on scroll
    • table with alternate color rows

    jQuery Events

    • Javascript/jQuery - disable right click
    • jQuery - text input field - change keyup and paste events
    • trigger click using jQuery or Javascript

    jQuery DOM

    • jQuery html() vs text()
    • Check if an element exists
    • find total DOM elements
    • jQuery encode string to html entities
    • jQuery - read and modify iframe content
    • jQuery - create iframe with content
    • jQuery - find select element selectedIndex, value and text
    • jQuery - get checkbox value and checked state
    • jQuery - get javascript object

    jQuery Cookbook

    • get jQuery version
    • jQuery - add text to existing div
    • jQuery sliding effect - slideUp, slideDown, slideToggle

    jQuery UI

    • jQuery UI make element movable
    • jQuery ui slider and input text box - one way binding
    • jQuery ui slider and input text box - two way binding
     
    • Home
    • > Tutorials
    • > Javascript
    • > jQuery

    How to use fitvids.js for automatically resizing videos

    By admin | Last updated on Apr 8, 2016

    Fitvids (github link) is an open source javascript library built by Chris Coyier and Paravel which makes the width of videos in a web page fluid. To be precise, videos within a DOM element.

    How fitvids works

    It a pretty nifty piece of javascript. Here is how it works.

    1. Its wraps the video in a wrapper div with 100% width (no height setting)
    2. The wrapper div has a padding-top according to the aspect ratio ( height/width*100%). e.g. If height is half of width, it is 50%.
    3. The video element’s original height and width are removed and both are set to 100%.
    4. The video element is positioned in the wrapper div with css style position:absolute. This ensures that video element just fits in the padding of the parent wrapper div. Please note that had it been position:relative, the video element would have started after the padding.

    For complete code here is github link.

    Fitvids Demo

    In this example we display a video where fitvids.js has not been applied. You can resize the page and see what happens to the video. The video should not resize. Once you click on “apply fitvids code”, the following code is executed.

    jQuery('body').fitVids();
    

    Now video should resize with resize of the page.

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="/js/jquery.fitvids.js"></script>
    
    <iframe width="560" height="315" src="http://www.youtube.com/embed/NxJ0W-yz0LQ" frameborder="0" allowfullscreen></iframe>
    
    <br/><input type=button id="button1" value="click here to apply fitvids code" />
    <div id="msg"></div>
    
    <script type="text/javascript">
      jQuery("#button1").click(function() {
        jQuery('body').fitVids();
        jQuery('#msg').text('fitvids applied...');
      });
    </script>
    refresh done
    try it online

    Suggested posts:

    1. How to edit animated gif speed (FPS) using imagemagick convert
    2. Javascript local and global variables
    3. jQuery how to load a url into an element
    4. CSS general sibling selector
    5. HTML5 – video tag
    6. Make an element draggable using Vanilla Javascript
    7. CSS – drop cap effect
    8. HP 2515 printer review (deskjet ink advantage all-in-one)
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged CSS, Javascript, jQuery, Tutorials
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress