New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

source-media-query-loader

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

source-media-query-loader

Load image according to media queries and source nodes

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

source-media-query-loader

Load image according to media queries and source nodes

Install

npm i source-media-query-loader

API

QueryLoader(cb)

Create instance with the callback

The callback receive an object with 8 properties

ArgumentValue
srcthe image source
widththe image naturalWidth
heightthe image naturalHeight
mediathe media query
imgthe image node
xthe x focus point ratio, default to .5
ythe y focus point ratio, default to .5
attributesan object with the original attributes values
var ql = QueryLoader(function(data) {
  // {src:"image.jpg", width:320, height:240, media:"(max-width: 700px)", img:img, x:.5, y:.5, attributes:object}
  console.log(data)
})

ql.start()

add(data)

Add a source to the QueryLoader

Argument data can be a dom node or a javascript object

FormatValue
node<source src="image.jpg" media="(width <= 700px)"/>
object{src:"image.jpg", media:"(width <= 700px)"}

The properties src and media are required

find(node)

Add all <source> child of node

<div id="ref">
  <source src="small.jpg" x="0.663774403" y="0.375375375" hd="small-hd.jpg" media="(width <= 700px)"/>
  <source src="medium.jpg" x=".363" y=".484257871" media="(900px >= width > 700px)" />
  <source src="large.jpg" media="(width > 900px)" />
</div>
ql.find(document.querySelector('#ref'))

start([node], [offset])

Start the instance

If node is defined, starts the lazy loading mode. The image will be loaded if node will enter the viewport

The argument offset is only used in lazy mode. The argument is optional, default to 200

stop()

Stop the instance. The callback will no more be invoked

kill()

Kill the instance. Listeners and memory are cleared

License

MIT

Keywords

source

FAQs

Package last updated on 25 May 2016

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