🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@threespot/fluid-iframe

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@threespot/fluid-iframe

Make iframes responsive

1.0.2
latest
Source
npm
Version published
Weekly downloads
6
20%
Maintainers
2
Weekly downloads
 
Created
Source

Fluid Iframe

npm Build Status Coverage Status

Allows iframes to scale down while maintaining its original aspect ratio. This is most useful for iframes authors paste into a rich-text WYSIWYG field. Managed iframes whose markup can be controlled directly (e.g. shortcodes) can achieve this with just HTML and CSS.

Inspired by FitVids.js and noframe.js.

Install

yarn add @threespot/fluid-iframe

Usage

import FluidIframe from "@threespot/fluid-iframe";

const iframes = document.querySelectorAll("iframe");

iframes.forEach(el => new FluidIframe(el));

// Using a class instead of inline styles
iframes.forEach(el => new FluidIframe(el, {
  inlineStyles: false,
  classes: "video-wide"
}));

// Adding styles directly to the iframe with no wrapper
// (mean iframe won’t be able to expand beyond its original size)
iframes.forEach(el => new FluidIframe(el, { wrap: false }));

Here’s an example of how to use CSS instead of inline styles (requires wrapper around iframe):

  // wrapper div around the iframe
  .video-wide {
    position: relative;

    &:before {
      content: '';
      display: block;
      padding-top: percentage(9/16);
    }

    iframe {
      height: 100%;
      left: 0;
      position: absolute;
      top: 0;
      width: 100%;
    }
  }

Options

These options can also be set in JavaScript:

  new FluidFrame(el, {
    defaultAspectRatio: 9 / 16,
    forceRatio: false,// set aspect ratio to use regardless of actual dimensions of iframe
    inlineStyles: true,// apply inline styles to wrapper or iframe (depends on wrap option)
    wrap: true,// adds a div wrapper around the iframe
    classes: "" // class(es) to add to the wrapper or iframe (depends on wrap option)
  });

License

This is free software and may be redistributed under the terms of the MIT license.

About Threespot

Threespot is an independent digital agency hell-bent on helping those, and only those, who are committed to helping others. Find out more at https://www.threespot.com.

Threespot

Keywords

expand

FAQs

Package last updated on 06 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts