Created
April 18, 2017 04:36
-
-
Save andyhqtran/5022ddf4c26a681386629965324b6f2b to your computer and use it in GitHub Desktop.
Alert Banner for Divi Code Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Alert Banner --> | |
<div class="at-alert-banner" data-alert-id="1"> | |
<!-- Content --> | |
<div class="at-alert-banner__content"> | |
<!-- Banner Text --> | |
<div class="at-alert-banner__text">Custom Text Here</div> | |
<!-- Banner Button --> | |
<a class="at-alert-banner__button" href="https://custom-url-goes-here.com">Custom Text Here</a> | |
</div> | |
<!-- Close Button --> | |
<div class="at-alert-banner__close">X</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function() { | |
var alertBanner = jQuery('.at-alert-banner'); | |
var alertBannerId = alertBanner.attr('data-alert-id'); | |
/* If localStorage key exist, hide banner */ | |
if (localStorage["at-alert-" + alertBannerId]) { | |
alertBanner.hide(); | |
} | |
/* Click event handler */ | |
alertBanner.find('.at-alert-banner__close').on('click', function() { | |
/* Hide alert banner when clicked on close button */ | |
jQuery(this).closest('.at-alert-banner').hide(); | |
/* Set item in local storage based on id provided */ | |
localStorage.setItem("at-alert-" + alertBannerId, true); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Alert Banner */ | |
.at-alert-banner { | |
z-index: 999999; | |
position: fixed; | |
top: 0; | |
right: 0; | |
left: 0; | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-orient: horizontal; | |
-webkit-box-direction: normal; | |
-ms-flex-direction: row; | |
flex-direction: row; | |
-webkit-box-align: center; | |
-ms-flex-align: center; | |
align-items: center; | |
background: #0080FF; /* Editable, Banner Background Color */ | |
width: 100%; | |
height: 100px; /* Editable, Banner Height */ | |
box-sizing: border-box; | |
-webkit-transform: translateY(-150%); | |
transform: translateY(-150%); | |
color: #FFFFFF; /* Editable, Banner Text Color */ | |
font-family: "Open Sans", sans-serif; /* Editable, Banner Font Family */ | |
-webkit-animation: at-banner-slide-in 0.8s ease forwards; | |
animation: at-banner-slide-in 0.8s ease forwards; | |
} | |
/* Note, changes color of all links except button */ | |
/* Alert Banner - Link */ | |
.at-alert-banner a:not(.at-alert-banner__button) { | |
color: #FFFFFF; /* Editable, Banner Link Color */ | |
} | |
/* Alert Banner - Content */ | |
.at-alert-banner__content { | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-align: center; | |
-ms-flex-align: center; | |
align-items: center; | |
-webkit-box-orient: horizontal; | |
-webkit-box-direction: normal; | |
-ms-flex-direction: row; | |
flex-direction: row; | |
-ms-flex-wrap: wrap; | |
flex-wrap: wrap; | |
-webkit-box-pack: center; | |
-ms-flex-pack: center; | |
justify-content: center; | |
max-width: 1100px; /* Editable, Banner Content Max Width */ | |
margin: 0 auto; | |
padding: 0 20px; | |
box-sizing: border-box; | |
} | |
/* Alert Banner - Text */ | |
.at-alert-banner__text { | |
margin: 0 20px 0 0; | |
} | |
/* Alert Banner - Button */ | |
.at-alert-banner__button { | |
display: inline-block; | |
background: #FFFFFF; /* Editable, Banner Button Background Color */ | |
height: 40px; | |
border: 0; | |
border-radius: 2px; | |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | |
padding: 0 20px; | |
color: #0080FF; /* Editable, Banner Button Text Color */ | |
font-size: 12px; | |
font-weight: 700; | |
line-height: 40px; | |
text-decoration: none; | |
white-space: nowrap; | |
-webkit-transition: box-shadow 0.2s ease; | |
transition: box-shadow 0.2s ease; | |
} | |
.at-alert-banner__button:hover { | |
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); | |
} | |
/* Alert Banner - Close */ | |
.at-alert-banner__close { | |
position: absolute; | |
top: 50%; | |
right: 20px; | |
width: 20px; | |
height: 20px; | |
-webkit-transform: translateY(-50%); | |
transform: translateY(-50%); | |
cursor: pointer; | |
} | |
.at-alert-banner__close:before, .at-alert-banner__close:after { | |
content: ""; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
display: block; | |
background: #FFFFFF; /* Editable, Banner Close Color */ | |
width: 100%; | |
height: 3px; | |
border-radius: 2px; | |
-webkit-transform-origin: center; | |
transform-origin: center; | |
} | |
.at-alert-banner__close:before { | |
-webkit-transform: translate(-50%, -50%) rotate(-45deg); | |
transform: translate(-50%, -50%) rotate(-45deg); | |
} | |
.at-alert-banner__close:after { | |
-webkit-transform: translate(-50%, -50%) rotate(45deg); | |
transform: translate(-50%, -50%) rotate(45deg); | |
} | |
/* Alert Banner Animations */ | |
@-webkit-keyframes at-banner-slide-in { | |
0% { | |
-webkit-transform: translateY(-150%); | |
transform: translateY(-150%); | |
} | |
100% { | |
-webkit-transform: translateY(0%); | |
transform: translateY(0%); | |
} | |
} | |
@keyframes at-banner-slide-in { | |
0% { | |
-webkit-transform: translateY(-150%); | |
transform: translateY(-150%); | |
} | |
100% { | |
-webkit-transform: translateY(0%); | |
transform: translateY(0%); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment