Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jamescoyle/v-ratio

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jamescoyle/v-ratio

A vue directive for aspect ratio element sizing

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

v-ratio

Vue directive for fixed aspect ratio elements.

Installation

Yarn

yarn add @jamescoyle/v-ratio

NPM

npm install @jamescoyle/v-ratio

Global Installation

The following installs the directive globaly for your project. This is recommended for most cases as it is the easiest to set up and use throughout your project.

import Vue from 'vue'
import ratio from '@jamescoyle/v-ratio'

Vue.directive('ratio', ratio)

Local Installation

You can also use this directive by attaching it directly to a component. This method is recommended for components which are desinged to be portble as it packages the dependency into the component.

import ratio from '@jamescoyle/v-ratio'

export default {
    directives: {
        ratio,
    }
}

Usage

<div v-ratio="16/9">16:9 element. Set the width and the height will be automatically set.</div>
<div v-ratio:width="16/9">16:9 element. Set the width and the height will be automatically set.</div>
<div v-ratio:height="16/9">16:9 element. Set the height and the width will be automatically set.</div>

Resize Observer Polyfill

This directive makes use of the resize observer. This means that you will likely need to include a polyfill to improve browser support.

Install the resize observer polyfill and then include the following code wherever you placed the code from the installation section above. This will try to use the native implementation if it exists and then will fall back to the polyfill in browsers which don't support the resize observer.

import ResizeObserverPolyfill from 'resize-observer-polyfill'

const ResizeObserver = window.resizeObserver || ResizeObserverPolyfill

Please note that this may cause issues if browsers don't implement the resize observer in the same way or if the specification changes. I do not believe this will be the case however as the syntax for an observer is very mature at this point and it is unlikely that the resize observer will deviate from other observers.

Keywords

FAQs

Package last updated on 05 Apr 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc