0.2.5 • Published 5 years ago

media-view-component v0.2.5

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Built With Stencil

Media View Component

<media-view> is a Web Component that acts as an abstraction for the <img> and <video> elements and makes fitting and panning over them easy. Use the src attribute like normal and the media-view component will figure out if it's dealing with an image or a video.

Installation

Script tag

  • Put this script tag <script src='https://unpkg.com/media-view-component/dist/mediaviewcomponent.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

Node Modules

  • Run npm install media-view-component --save
  • Put this script tag <script src='node_modules/media-view-component/dist/mediaviewcomponent.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

In a stencil-starter app

  • Run npm install media-view-component --save
  • Add an import to the npm packages import media-view-component;
  • Then you can use the element anywhere in your template, JSX, html etc

Usage

Just place the <media-view> anywhere you would otherwise have used an <img> or <video> element. Supply a src attribute or set the mediaViewSource property on the element from code and it will load and display the media. If you know beforehand that the source is an image or video, you can use the optional srcType attribute.

<media-view src="https://www.fillmurray.com/420/560"></media-view>
<media-view src="https://www.fillmurray.com/420/560" srcType="image"></media-view>

A default loading spinner and error message are included, but if you want to show something else at those times, you can use the "loading" and/or "error" slots like this:

<media-view src="https://www.fillmurray.com/420/560">
  <div slot="loading"><span class="my-own-fancy-spinner">turn turn turn</span></div>
  <h1 slot="error">Something went horribly wrong!</h1>
</media-view>

Below is an overview of all the available properties on the <media-view> element. Also see a collection of examples here.

Properties

PropertyAttributeDescriptionTypeDefault
fitfit(optional) The kind of "object-fit" to use for the image/video. Can be contian, cover, fill, none, scale-down or pan.string"contain"
looploop(optional) Set to true to loop if the source is a videobooleanfalse
mediaViewSource--Use to set the mediaSource object directly. Use either this or the src property.MediaViewSourcenew MediaViewSource()
panDirectionpan-direction(optional) The direction in which the panning starts. Accepts 'normal' (up for tall media, right for wide), 'reverse' (down for tall media, left for wide) or 'random'.string"normal"
panEndAtCenterpan-end-at-center(optional) Set to false to prevent panning back to the center after all iterations are done.booleantrue
panIterationspan-iterations(optional) Set the number of iterations (passes) of the panning animation. Only accepts whole numbers and Infinity.number1
panMinVisiblepan-min-visible(optional) The minimum percentage of the media surface that is garanteed to be visible at any point during the panning.number80
panPausedpan-paused(optional) Set to true to pause the panning animation.booleanfalse
panTimepan-time(optional) Duration in seconds of a single iteration (pass), not counting returning to center.number5
pausedpaused(optional) Set to false to start playing if the source is a video.booleantrue
playStartplay-start(optional) Time in seconds to start playing from (and loop back to) if source is a video.numbernull
playTimeplay-time(optional) Time in seconds to play if source is a video.numbernull
srcsrcThe source url of the image/video. Use either this or the mediaSource property.stringundefined
srcTypesrc-type(optional) The source type. Can be either "image" or "video". If unspecified, the component will figure it out.stringundefined

Events

EventDescriptionType
mediaLoadedFires when the image/video is loaded.CustomEvent<any>
mediaSourceInvalidFires when the image/video could not be loaded.CustomEvent<any>
playEndedFires when the video stopped playing.CustomEvent<any>
playStartedFires when the video starts playing.CustomEvent<any>
0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago