MacBook Air Website Content Toggle

Earlier this week Apple released a brand new Mac Book Air with a lovely new web page. :heart_eyes:

I was scrolling through it when I saw a section that caught my eye and decided to remake it in Blocs 6 Plus using a combination of classes and a custom interaction.

This is what the end results looks like, click the + button bottom right to reveal a second pane of information.

Outcome

I wanted to make this a re-usable section so that it could be easily used multiple times on the same site/page, here is how I did it.

The Interaction :zap:

The custom interaction for this one is surprisingly simple, I use a toggle class interaction rule and I feed the target ID from the interaction trigger using data() to feed in the data attribute value data-section.

The Structure :building_construction:

The entire component in housed in a single Div, that uses CSS Grid applied by a class so that I can get the two slides sections to overlap each other.

As you can see from this screen shot, the section has an ID applied (display-section). This main container div is the element my Custom Interaction toggles the alt-state class on.

The Trigger :gun:

The trigger for the interaction is the little plus + button.

On this icon I have a click interaction set (Toggle Slide) and also a custom attribute data-section which is populated with the ID of the main container display-section.

When the trigger is clicked it passes the data-section value into the Custom Interaction which will use this value as the ID of the element to toggle the alt-state class on. :nerd_face:

The Animation

All of the animation is done using CSS transitions, transforms and a class to toggle it on and off for all elements at once.

If you look at the project you will see all animated elements have a base class e.g. .slide-1 and a second class with the alternative state e.g. .alt-state .slide-1

When the container doesn’t have have this alt-state class each element looks one way and when this class is added to the parent div container that original class is overridden with new values, because CSS transitions are used in the classes it animates. :sparkles:

Rather than get into the weeds with how I animated each part, just take a look at the classes on the parts that animate. :index_pointing_at_the_viewer:

How to Re-use :zap::zap:

As I mentioned at the start, this component is created so you can reuse it within a project easily. All you have to do is duplicate the main div that houses everything. Then change its ID and also update the trigger custom attribute data-section to this new ID.

Final Details :information_source:

If you want to access the second pane of details for editing just select the main div container for component and apply the alt-state class to it. It will then show the hidden part of the UI.

Because the toggle control is managed within an Custom Interaction, it means you can apply more actions when the toggle is clicked if you want. Maybe play a sound, auto play a video on the second slide, or store a cookie to mark that the visitor has accessed this part of the website. Lots of possibilities now that this is done with a Custom Interaction.

Anyway that wraps this one up, as always you can download the experiment project below (Requires Blocs 6.1 beta 3 Minimum) :point_down:

Apple Content Toggle Experiment V2.bloc (1.2 MB)

10 Likes

That’s very cool and inspirational! Thanks for sharing :+1:

2 Likes

WHOOOOOOSH!
And there it went straight over my head, but well done!

2 Likes

Looks like you’re having so much fun toying with Interactions features in Blocs 6. It’s like you’re inviting us to jump in the sand box to see what can be done. :smiley:

3 Likes

Bloody brilliant!!! Great work @Norm

2 Likes

Thanks :grinning:

My goal is to demonstrate what is possible without using code using only Blocs.

At times these examples will be intricate and require learning, but if you don’t know how to code you will find what you learn in these examples very useful.

6 Likes

I’ve made a few tweaks to the experiment example file, the trigger is now the actual icon rather than a container div, thanks to the improvements in Blocs V6.1 beta build 3.