top of page
Alert Messages

Alert Messages

Display an alert popup message on the corner of the screen

Intermediate.png

Advanced

1

Published:

February 24, 2021

Anchor 1
Hire a Developer

Example Description

In this example, site visitors can create small alert messages and have them pop up on the corner of the screen. Visitors can customize the alert’s title, message, type (error, success, info or warning), position, color, etc. The alert is implemented using a custom element.


Note: Only premium Wix users on sites with their own domain and Wix ads removed can work with custom elements.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It


Page Elements


The page includes the following elements:


  • An alert custom element

  • Text inputs, dropdowns, buttons and a switch that allow site visitors to customize the alerts according to their need



Page Code


The onReady function sets the following event handlers:


  • Show Alert button on Click - validates that the message text input is not empty and then creates an object that includes the chosen alert configuration and passes this object to the alerts backend function.


  • Position dropdown onChange - sets the position attribute of the custom element to the chosen screen position using the setAttribute function.


  • Clear button onClick - reverts all the configuration options back to the original configuration.



Public code


The alerts.js backend file includes two functions:


  • alert - runs validations on the input. Then it calls the newAlert function and passes the alert configurations object to it.


  • newAlert - sets the attribute of the custom element to a new alert according to the requested configuration. Each time this function is called it increments the count property of the configuration object so that the object is unique even if the same configuration is sent more than once.



Custom element


The custom element is in charge of displaying the alert according to the chosen configuration. The alert sticks to any side of the screen, includes animations and is fast. You can learn more about the custom element and view it's code on github.


By default, the alert will auto close after 8 secs. Once closed it will trigger the onClose function of the custom element. If the alert is clicked it will trigger the onAction function of the custom element.

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Dropdown Custom Element

Dropdown Custom Element

Create a dropdown with text and images using a custom element.

Intermediate.png

Advanced

Chart.js Custom Element

Chart.js Custom Element

Use custom elements to implement a chart of countries and votes per country.

Intermediate.png

Advanced

Anchor 2
bottom of page