Image Mask Effect
An immersive transition effect powered by image masks and CSS transforms.
We’ve been publishing in our library some nice mask effects powered by SVG properties. This time we took advantage of the PNG transparencies to zoom through the mask layer, into a project background image.
If you want to change the color of the .png masks, you can easily do it in Photoshop (or any other graphic tool) by applying a color overlay to the whole image layer. If you plan to create your own masks, please note that this effect works only if there’s an empty space in the very center of the mask.
Creating the structure
The HTML structure is composed of a list of
<section>
s wrapped in a .cd-image-mask-effect
element. Each <section>
contains a div.featured-image
(project image), a div.mask
(image mask) and a div.cd-project-info
for the project content.
The project content is not included in the HTML but is loaded using JavaScript.
Adding style
Each
Four
.cd-project-mask
has a height of 100vh (viewport height) and a width of 100%; the project image is set as background-image of the .featured-image
element, while the mask image is wrapped inside the .mask
element.Four
.mask-border
elements have been used to create a frame around the image mask to make sure the project featured image is not visible outside the mask (we used <span> elements rather than pseudo elements because their behaviour was buggy on Safari 9).
When the user selects a project, the class
The
.project-view
(added to the wrapper .cd-image-mask-effect
) is used to hide all the other projects.The
.mask
element is then scaled up to reveal the project featured image and the project content is loaded (more in the Events handling section).Events handling
To implement this image mask effect, we created a
ProjectMask
object and used the initProject
method to attach the proper event handlers.
When the user selects a project, the
revealProject
method is used to scale up the mask image while the uploadContent
method takes care of loading the project content (using the load()
function) and adding the new page to the window.history (using the pushState()
method).