Hype Action Events

Example using Matter collisions events

data-collision-start-action
data-collision-end-action


Here is a simple demo that continues its fall by being reset

Version with inline code:
Example_Data_Attribute_Matter_Collisions.hype.zip (46,1 KB)

Version using a single Hype function (switch on event.type):
Example_Data_Attribute_Matter_Collisions_Hype_function.hype.zip (46,8 KB)

CleanShot 2022-01-25 at 11.56.26


↑ look at project
1.0.5 Fixed typo that prevented collision events to be detected
Make sure to purge your Browser cache and restart Hype when using examples after I made an GitHub update!

4 Likes

Example using Animation Frame events

data-animation-frame-action


Here is a simple shadow animation driven by the ball element
Example_Data_Attribute_Matter_Animation_Frame.hype.zip (29,3 KB)

4 Likes

↑ look at project
1.0.6 Added hypeDocument, element and event to the triggerAction context, added data-behavior-action


Add your actions on specific element using custom behavior triggers.

data-behavior-action listens to all behavior names
data-behavior-test-action would only listen to the test behavior name*


* behavior names are lower cased and spaces/tabs are replaced with dash. Hence, a behavior like Hello World --- Test would become hello-world-test and the full action hook would be data-behavior-hello-world-test-action

2 Likes

Example using hypeDocument.triggerAction and Symbol Handler


Here is a simple switch button using hypeDocument.triggerAction and also showing how Hype Action Event triggers a function handler named like a symbol if found on HypeSymbolLoad and HypeSymbolUnload (proactive).

Example_Switch_Button_Symbol.hype.zip (47,3 KB)

CleanShot 2022-02-04 at 00.20.33

2 Likes

↑ look at project
1.0.7 Added data-timeline-complete-action, hypeDocument.triggerActionsByAttribute and minor refactoring


1.0.8 Bugfix on data-timeline-complete-action for particular timelines


You can now trigger actions when a timeline completes using data-timeline-complete-action for all timelines or if a specific timeline completes like test it would be data-timeline-complete-test-action

3 Likes

Example of using Hype Drag Gesture


This example uses Hype Action Events, Hype Matter Helper and Hype Drag Gesture to offer drag and drop support with precise drop zones and snapping. Note that this drag'n'drop approach relies on the Matter engine offered by Tumult Hype to determine arbitrary shape intersections. Hence, the export will include the physics engine.

This gesture offers the following events:

data-drag-start-action
data-drag-move-action
data-drag-end-action
data-drop-success-action
data-drop-fail-action
data-intersection-start-action
data-intersection-end-action

And the following selector defining the drop target

data-drop-selector 

This example also uses a snapping mechanism, data-snap-target, but that is specific to this particular example and implemented in the document rather than being part of the gesture.

Example_Hype_Drag_Gesture.hype.zip (177,4 KB)

2 Likes

Another Example using the document scroll event

data-document-scroll-action


With this demo, I am actually not so sure if I do it in such a way in an actual production (hence, the title of experiment). I would probably rather have the entire sticky element be one symbol and use a progress function. In this example file, there is a lot of whitespace just to have room to scroll to drive progress.


The following data attributes can be used to control the behavior of the scroll progress handler:

data-sticky-start: This attribute allows you to set a custom start position for the element's sticky behavior. If this attribute is not set, the element will become sticky when it reaches the top of the page.

data-sticky-end:
This attribute allows you to set a custom end position for the element's sticky behavior. If this attribute is not set, the element will remain sticky until the user scrolls to the bottom of the page.

data-sticky-bounding:
This attribute allows you to set a bounding box for the element's sticky behavior. If this attribute is set, the element will become sticky when it reaches the top of the bounding box, and will remain sticky until the user scrolls to the bottom of the bounding box.


There is a little progress handler action in the example as well (bonus):

data-progress-start:
The top position (in pixels) of the scrollable area.

data-progress-end:
The bottom position (in pixels) of the scrollable area.

data-progress-timeline:
The name of the timeline to be played (defaults to main timeline)


Example_Data_Attribute_Document_Scroll_Experiment.hype.zip (298,8 KB)


Effect was inspired by the page Apple Fitness+ - Apple and the images are from Unsplash

4 Likes

Example of using Hype Slide Gesture

This example is a refactored version of the custom continueAfterDrag functionality. It offers more options and settings than the regular version, built in to Hype.

This gesture offers the following events:

data-timeline-drag-start-action
data-timeline-slide-move-action
data-timeline-slide-end-action
data-timeline-drag-start-action
data-timeline-drag-end-action

The following config options are available

  • minVelocity Set the min velocity. Use only in special cases as it can lead to infinite movement after drag
  • maxVelocity Often a good way to avoid to high values after a drag'n'slide gesture
  • friction defaults to 0.95 and slows down the velocity of the continued drag on each tick. This adds an organic feel to the movement.
  • forceInstance, symbolInstance (can be used to add symbolInstance or hypeDocument, is auto-detected inside of symbols in favor of the symbol)
  • timelineName is the name of the timeline and default to the Main Timeline of either the hypeDocument or the symbolInstance
  • borderMode defaults to none as seen in regular Hype, and the movement just stops at the end or beginning. Using bounce allows bouncing of the end and beginning. In such an event, there is an additional friction applied. Finally, there is the shift mode, and it allows overshoots at the end or beginning. As we are talking about a timeline, this means the timeline restarts in the current play head direction.
  • borderFriction defaults to a factor of 0.1 and is only applied if the borderMode is set to bounce. Setting this to 0.9 allows for much more bouncing.
  • threshold this defaults to 0.01 and is the threshold the velocity must be under to trigger an end for a slide action

Example_Hype_Slide_Gesture.hype.zip (83,2 KB)

CleanShot 2022-02-10 at 15.41.32

1 Like

Example zooming a map and hiding offscreen elements

data-intersection-action
data-scene-prepare-action
data-pointerdown-action



There is a alternative version (only zoom) using a single SVG here

3 Likes

Example to determine offline mode and online connectivity

data-window-online-action
data-window-offline-action


Example to determine the visibility of a browser tab

data-document-visibilitychange-action


1 Like

↑ look at project
1.0.9 Removed blur and focus and added focusin and focusout instead, moved contextmenu, keydown, keypress, keyup and submit events to non passive allowing event.preventDefault(), higher execution order on Hype functions

2 Likes

Example demonstrating form-based events like focus and change

data-focusin-action
data-focusout-action
data-change-action


CleanShot 2022-02-16 at 19.41.57

Example_Data_Attribute_Focus_And_Change.hype.zip (29,2 KB)

1 Like

Example demonstrating event bubbling and closest action feature

data-pointerover-action
data-pointerout-action
data-pointermove-action


This example demonstrates multiple features. Foremost, the event bubbling aspect in combination with the latest update (1.0.9+) using the closest action match. This allows to embed an SVG into a rectangle, in this case a map*. The event is only defined in Hype on the rectangle but is triggered by all path elements in the SVG.

CleanShot 2022-02-16 at 22.22.15

Example_demonstrating_event_bubbling_and_closest_feature.hype.zip (81,0 KB)


Here is another version with transitions, ID and Name to CSV and dynamic tooltip positions:

Example_demonstrating_event_bubbling_and_closest_feature_transition_tooltip_pos.hype.zip (81,9 KB)


Map from simplemaps, all administrative regions are identified by name and id in the SVG source code. Find more maps and regions at Free SVG Maps - Resources | Simplemaps.com (they are free for commercial use, attribution is optional).

6 Likes

Yet, another example playing around with scroll

data-document-scroll-action


Example_playing_around_with_scroll_Mary_Cassatt.hype.zip (385,4 KB)

4 Likes

Example connecting two rectangles (Hype elements) with an SVG line

data-mutation-action
data-scene-load-action


CleanShot 2022-02-17 at 17.46.15

↑ look at project
1.1.0 Added hypeDocument.querySelector and hypeDocument.querySelectorAll, minor fixes

I am back after :microbe: :chart_with_downwards_trend: :mask: :face_with_thermometer: … was a real shocker, get vaccinated, I am glad I was…

4 Likes

Welcome back!

1 Like

Another example demonstrating form-based change

data-change-action


This example demonstrates the versatility to define an action handler inside a rectangle (div) or on the Additional HTML Attribute.

CleanShot 2022-02-26 at 00.32.27
Example_Data_Attribute_Change_with_a_select.hype.zip (38,0 KB)

1 Like

Example on creating your own event

data-apex-marker-click-action


4 Likes