You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit adds new functionality to postpone. You can now set the
threshold, the distance before an edge at which an element should be
considered to be at the edge and loaded. The threshold can be specified
in either `vh` or `px` units.
Copy file name to clipboardExpand all lines: Readme.md
+25
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,28 @@ var Postpone = require( "postpone" );
30
30
postpone =newPostpone(); // Creates a new instance and starts watching the document.
31
31
````
32
32
33
+
By default, postpone will load an element's resource when that element scrolls into the viewport, however, you may want postpone to start loading your resources a bit before they scroll into view to ensure that they are available by the time they are on screen. Postpone lets you do this easily by passing a parameter to the constructor. If you feed postpone a number, postpone will assume you are using `vh` units, however you can also feed it a string with explicit units, such as `"150px"` or `"30vh"`. Currently, only `vh` and `px` units are supported.
34
+
35
+
````js
36
+
var Postpone =require( "postpone" );
37
+
38
+
postpone =newPostpone( 50 ); // Postpone will set the threshold to 50vh, or half a viewport.
39
+
````
40
+
41
+
Optionally, you can manually change the threshold at any point in your code by calling the `.setThreshold()` method.
42
+
43
+
````js
44
+
var Postpone =require( "postpone" );
45
+
46
+
postpone =newPostpone() // Threshold defaults to 0vh
47
+
48
+
...// Do something with our code.
49
+
50
+
postpone.setThreshold( "200px" ).postpone() // Change the threshold to 200px.
51
+
````
52
+
53
+
*Note:* we chain the `postpone()` method after changing the threshold to make sure postpone reexamines the postponed elements in the document and check if any of them should be loaded.
54
+
33
55
The postpone polyfill works with audio, embed, iframe, img, image, picture, use, video, and tref elements. *Note:* although the specification for `picture` is still evolving, postpone has basic support for it and is fully compatible with the [pictureTime polyfill](https://github.com/chuckcarpenter/picturetime).
34
56
35
57
Postpone works by modyfing the `src` and `xlink:href` attributes of elements and their descendant `source` elements when they become visible.
@@ -58,6 +80,9 @@ postpone = new Postpone(); // Creates a new instance and starts watching the doc
58
80
### .load(element)
59
81
Stop postponing the download of your `element` by manually telling postpone to load it.
60
82
83
+
### .setThreshold([threshold])
84
+
Set postpone's threshold, the distance away from an edge of the viewport at which an element should be considered to be at the edge and thus loaded. `setThreshold()` accepts one optional argument and can be called at any point. The argument can be a string representing a distance in either `vh` or `px` units, a number, in which case the threshold will be interpretted as having `vh` units, or empty, effectively setting the threshold to 0.
0 commit comments