Friday, July 26, 2019

Best Free WordPress Audio Player Plugins

Create a Blog for Each Category or Department in Your WooCommerce Store

20 Professional Email Newsletter Templates for Mailchimp to Connect With Customers in 2019

25 Animated Keynote Templates to Make Amazing Presentations in 2019

25 Cool Business Card Designs (Creative Inspiration + Ideas for 2019)

New Course: A Guide to Animation Performance on the Web

Affinity Publisher: Your Guide to InDesign’s New Rival

How to Turn a Landscape Photograph Into an Isometric Icon in Adobe Photoshop

Thursday, July 25, 2019

Create Amazing Prototypes in No Time with the Envato Elements Sketch Plugin

New Course on the WordPress Customizer for Theme Designers

25 Best Keynote Pitch Deck Templates (Business Plan Presentation Designs)

20 Top Wedding Slideshow Ideas (With Wedding PowerPoint Template Examples)

25+ Best Free Professional Business PowerPoint Design Templates (2019 PPT Downloads)

5 Easy Rules for Mobile UI Design Beginners

How to Use the Project, Composition and Timeline Panels in After Effects

How to Create a Photo to Art Text Effect Photoshop Action

50 Awesome Photo Effect Tutorials

26 Best InDesign ePublishing Templates (Digital Magazines & eBooks)

Tuesday, July 23, 2019

Understanding Native, WebView, and Hybrid Templates for Android Apps

Understanding React Native Components, Templates, and Tools

Definitive Guide to Installing a (Free or Premium) WordPress Plugin

Getting Started With Agile Development Using monday.com

How to Create a Video Production Workflow With monday.com

2019 Business Card Design Guide to New Trends & Modern Styles

How to Conduct a UX Card Sorting Workshop

25+ Minimal Business Cards (With Simple Modern Design Ideas) for 2019

How to Create an Alarm Clock in Cinema 4D: Part 2

25 Best Baby Onesie Mockups (With a Onesie Mockup Generator)

How to Create a Magazine Cover Template in InDesign

Wednesday, July 10, 2019

15 Best Royalty-Free Electronica Music Tracks of 2019

Destructing Elements in 3ds Max with RayFire: Part 3

How to Add Graphic Design Services to Your Photography Business

New Course: Create a Pendulum Animation in Cinema 4D

25 Modern Keynote Templates for Beautiful Presentation Designs in 2019

How to Create Custom Blocks for Gutenberg

How to Create a 60s Retro Flyer Design

How to Recover Deleted Photos and Videos From an SD Card

How to Create a Space Travel Infographic in Adobe InDesign

Thursday, July 4, 2019

Quick Tip: How to Create a Metallic Text Effect Using Layer Styles in Photoshop

How to Draw & Paint a Beautiful Mermaid in Adobe Photoshop

Walk and Talk: How to Film Dialogue in Motion

Introduction to SVG Filters

25+ Professional PowerPoint Templates: For Better Business PPT Presentations

50+ InDesign Templates Every Designer Should Own

How to Create a Quick Broken Glass Text Effect in Adobe Photoshop

10 Design Tips for Creating Mouth-Watering Menus

Monday, July 1, 2019

How to Build a JavaScript Popup Modal From Scratch

How to Build a JavaScript Popup Modal From Scratch

In this tutorial we’ll learn how to build JavaScript popup modals (popup windows) without using a framework like Bootstrap, or a third party library. We’ll build the whole thing from scratch, giving us complete control over how it works and looks.

Here’s the demo we’ll be creating:

1. Begin With the Page Markup

First we’ll create a modal. To do this, we’ll add the .modal class and a unique ID to a container. Next we’ll specify the dialog by setting a .modal-dialog element as the direct child of the .modal. The dialog will hold the modal content. This can be any kind of content like text, images, lightboxes, user notifications/alerts, etc.

“A pop-up (or modal) is a small UI element that will appear in the foreground of a website, usually triggered as a prompt for the user to do something” – Adi Purdila

To open a modal, we’ll need any element with the data-open attribute (normally a button). The value of this attribute should be the ID of the desired modal.

By default, a modal will close if we click outside its boundaries or when the Esc key is pressed. But we can also close it if we click on any element with the data-close attribute (normally a button).

Initially the modal will appear/disappear with a fade effect. But we have the ability to adjust the animation effect of the dialog via the data-animation attribute. The value of this attribute which has to be added to the .modal can be any of the following values:

  • slideInOutDown
  • slideInOutTop
  • slideInOutLeft
  • slideInOutRight
  • zoomInOut
  • rotateInOutDown
  • mixInAnimations

We’ll have a closer look at these values in an upcoming section.

For now, let’s get familiar with the markup needed for representing a single modal: 

2. Define Some Basic Styles

With the markup ready, we’ll set up a few CSS variables and reset styles:

Next, we’ll horizontally and vertically center the page contents. Plus, we’ll give some styles to the button responsible for opening the modal:

At this point we’ll focus our attention on the modal styles.

Each modal will have the following characteristics:

  • It’ll be full-screen with a fixed position. That said, it will look like an overlay that covers the entire window’s width and height.
  • It’ll have a dark background color.
  • It’ll be hidden by default.
  • The dialog will be horizontally and vertically centered.

The dialog will have a maximum width and a maximum height. Its height will be 80% of the window height. In cases where its height exceeds that value, a vertical scrollbar will appear:

As a last thing, we’ll define a few straightforward styles for the individual content sections:


3. Toggle Modal

A page can have more than one modal. But as already discussed earlier, all modals will initially be hidden.

Open Modal

Similarly, a page can have more than one open triggers (elements with the data-open attribute). Each time a trigger is clicked, the associated modal should become visible with a fade-in animation. Remember the data-open attribute value has to match the ID of a modal.

Here’s the script which reveals a modal:

And the relevant CSS classes:

Close Modal

With our implementation only a single modal can appear at a time (this code doesn’t support nested modals). As mentioned in the markup section above, there are three methods available for hiding it with a fade-out effect.

Let’s recap.

Firstly by clicking on the custom [data-close] element which is located inside the modal:

Secondly by clicking on everything outside of the modal:

In this case the modal (overlay) behaves as a giant close button. For this reason we gave it cursor: pointer.

Lastly by pressing the Esc key:

Now is a good time to look at what we’ve created so far:

The modal looks pretty good! Notice that each time we click on an open trigger, only the corresponding modal loads.

Let’s take it one step further and examine some ideas for animating its dialog.

4. Add Dialog Animations

Like we said earlier, the default behavior of the modal is to fade-in and fade-out. But there’s the option to adjust the animation effect of the popup.

I’ve already created a bunch of animation effects which you can use as an alternative to the fade effect. To do this, just pass the data-animation="yourDesiredAnimation" attribute to the .modal.

For example, if you want the dialog to appear with a slide animation from left to right, you’ll need the slideInOutLeft effect.

Behind the scenes, there are two rules which accomplish this desired animation:

Check the modal with this type of animation here:

You can check the rest of the animations by looking at the CSS tab of the final demo project. Depending on the complexity of the animations, I’ve used either CSS transitions or animations to build them. 

I’ve also made use of the cubic-bezier() function for setting the timing function for all transitions. If you don’t like the bounce effect that produces, feel free to change it to something smoother via the --bounceEasing CSS variable.

Have a look at the final demo with all the animation effects here:

Conclusion

That’s it, folks! During this tutorial we learned how to build custom animated modal dialogs without relying on any front-end framework.

I hope you enjoyed the final result and building it helped refresh your front-end skills. 

Bear in mind that we haven’t considered accessibility, so if you want to enhance this demo that certainly could be the next step.

As always, thanks for reading!

More Popup Reading

  • WordPress Plugins
    20+ Best Popup & Opt-In WordPress Plugins
    Nona Blackman
  • UI Design
    The Best Way to Use Pop-Ups (Modals) in Your Web Design
    Adi Purdila
  • WordPress
    How to Create Awesome Popups in WordPress with Elementor Pro
    Adi Purdila

24 Essential Keyboard Shortcuts for After Effects

24 Essential Keyboard Shortcuts for Premiere Pro

25+ Attractive (Aesthetically Pleasing) PowerPoint Templates (Free + Premium Designs)

A Beginner's Guide to Adobe Illustrator Patterns

How to Create a Page Layout and Magazine Article Template in InDesign