Magic Modal Custom Interaction ✨

I have a brand new experiment to share with you here in the Custom Interactions lab. This new example demonstrate the flexibility we have with Custom Interactions when building with Blocs 6.1 and using the new data() short code.

In this example, I populate a single modal with different data based on the trigger element. This type of interaction could be useful for product popovers, but could easily be expanded to create your very own custom light box solution (if you felt adventurous).

Magic Modal

How it works :gear:

The setup for this type of interaction is very simple. Trust me :nerd_face:

  1. I have a single modal with a title, image and description text, which all have unique IDs assigned (including the actual modal).

  1. I then have a single Custom Interaction which will pull data from the trigger element using the data() short code to populate the title, description and set the image src path (including data-src for lazy load).

After I have set all of the data for each part of the modal (title, description and image) I also toggle the actual modals visibility (this shows the modal).

  1. Finally I set up the trigger element. I assign my custom interaction on the click event and I assign the custom data attributes required to populate the modal.

Pay close attention to the data attributes on the button such as data-title and how I use those in the actual interaction rules using the short code data(data-title).

Now if I duplicate the button multiple times and change the custom attributes data-title, data-desc and data-img-path on the duplicated button. I can get the same modal to show completely different information.

Pretty handy eh!

And of course here is the sample project file for you to play around with :grin:

This project requires Blocs for Mac 6.1 beta build 2 minimum

Magic Modal.bloc (367.3 KB)

Have fun :beers:

9 Likes

This is absolutely stunning! :exploding_head:

I managed to create an incredibly advanced page using this technique! I’ll share it with the community soon (it’ll be part of my new Blocs Master website).

4 Likes

Glad that helped :raised_hands:

I’m sure you will find all kinds of ways to use this :sunglasses:

1 Like

would this work with audio source too?

It wouldn’t work with the default audio Bric as you can not target the source element within it.

I do have plans for a dedicated player file setter rule. Which would address that shortcoming.

Obviously our goal is to avoid code, however, in the meantime, you could use a code Bric and add your player as code and then apply the ID to the source tag in the player using the set attribute rule.

1 Like

I’ll better wait for this :grin:

1 Like