How to Use the Extension
- Add the Extension to Your Project:
You can include the Hype Snapshot Properties Extension by either linking it via CDN or downloading it from the GitHub repository.
-
Option A: Content Delivery Network (CDN)
The latest version can be linked into your project using the following in the head section of your project:<script src="https://cdn.jsdelivr.net/gh/yourusername/HypeSnapshotProps/HypeSnapshotProps.min.js"></script>
-
Option B: Download from GitHub
- Go to the Hype Snapshot Properties Extension GitHub Repository.
- Download the latest version of
HypeSnapshotProps.js
orHypeSnapshotProps.min.js
. - Place the downloaded
HypeSnapshotProps.js
orHypeSnapshotProps.min.js
file in your Hype project's resources folder.
-
Set
data-snapshot-props
Attribute:- Add the
data-snapshot-props
attribute to any element you want to track. - Example:
data-snapshot-props
the value defaults totop,left
but you can also specify props liketop,left,width
- Add the
-
Trigger Updates Manually:
- Use
hypeDocument.snapshotProps(selectorOrElement)
to manually snapshot the properties. - Example:
hypeDocument.snapshotProps(hypeDocument.getElementById('myElement'));
- Example:
hypeDocument.snapshotProps('.myElements');
- Example:
hypeDocument.snapshotProps();
(Snapshots all elements withdata-snapshot-props
in the current scene) - Example:
hypeDocument.snapshotProps(hypeDocument.getElementById('myElement'), { top: 100, left: 200 })
;
- Use
-
Restore Properties with Optional Overrides:
- Use
hypeDocument.restoreProps(selectorOrElement, options)
to restore a specific element's properties or all elements matching the selector with optional overrides. - Example:
hypeDocument.restoreProps(hypeDocument.getElementById('myElement'), { duration: 2, easing: 'linear' });
- Example:
hypeDocument.restoreProps('.myElements', { duration: 0.5, easing: 'easeout' });
- Example:
hypeDocument.restoreProps();
(Restores all elements withdata-snapshot-props
in the current scene)
- Use
Explanation
-
Defaults:
The default properties to be tracked aretop
andleft
, with a default duration of 1 second for general defaults and 0.5 seconds for individual calls. Easing is set to 'easeinout' by default. These can be changed using thesetDefault
method. -
Document Load:
During theHypeDocumentLoad
event, thesnapshotProps
andrestoreProps
functions are added to thehypeDocument
object, making them available for manual updates and resets. -
Scene Preparation:
During theHypeScenePrepareForDisplay
event, the extension will look for all elements with thedata-snapshot-props
attribute and snapshot the specified properties. -
Snapshot Properties:
ThesnapshotProps
function can take either a selector string or an individual element to snapshot the properties. If called without parameters, it snapshots all elements withdata-snapshot-props
in the current scene. -
Restore Properties with Overrides:
TherestoreProps
function can take either a selector string or an individual element to restore the properties using the stored data attributes, with duration and easing specified bydata-snapshot-duration
anddata-snapshot-ease
attributes or their defaults. Optional overrides for duration, easing, and properties can be passed via theoptions
object. CallinghypeDocument.restoreProps()
without arguments will restore all elements withdata-snapshot-props
in the current scene.
--
Example and code
HypeSnapshotProps.hype.zip (36,8 KB)