Popup Notification will hide on scroll
A Pen by Zeinab Abounassif on CodePen.
<header> | |
<div id="darkBack"></div> | |
<div id="popUp"> | |
<div id="close" class="close"><i class="fa fa-times"></i></div> | |
<div id="new"><span>NEW!</span></div> | |
<h2>I'm a notification popup that isn't too distracting or in your face. Scroll down or close me and I will go away. You'll still be able to open me later on don't worry.</h2> | |
<br> | |
<a href="#" target="_blank" class="button">Visit Page</a> | |
</div> | |
<div id="plus"><span>NEW<br> <i class="fa fa-plus"></i></span></div> | |
</header> | |
<div id="body"></div> |
Popup Notification will hide on scroll
A Pen by Zeinab Abounassif on CodePen.
$(document).scroll(function() { | |
var scroll = $(this).scrollTop(); | |
if (scroll >= 150) { | |
$("#popUp").css("margin-left", "-425px"); | |
$("#plus").css("margin-left", "0px"); | |
} | |
}); | |
$("#plus").click(function() { | |
$("#popUp").css("margin-left", "0px"); | |
$("#plus").css("margin-left", "-425px"); | |
}); | |
$("#close").click(function() { | |
$("#popUp").css("margin-left", "-425px"); | |
$("#plus").css("margin-left", "0px"); | |
}); |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
* { | |
margin: 0; | |
font-family: 'Source Sans Pro', sans-serif; | |
} | |
a { | |
text-decoration: none; | |
} | |
header { | |
background: url(http://cdn.magdeleine.co/wp-content/uploads/2015/08/9524476479_ef867c36a4_o-1400x935.jpg); | |
background-size: cover; | |
background-position: center; | |
height: 100vh; | |
width: 100%; | |
} | |
#darkBack { | |
width: 100%; | |
height: 100vh; | |
background: rgba(76, 56, 75, .15); | |
} | |
#popUp { | |
position: fixed; | |
max-width: 350px; | |
height: 225px; | |
background: rgba(236, 240, 241, 1); | |
border: 7px solid #fff; | |
bottom: 0; | |
margin-left: 0; | |
-webkit-transition: all 1s ease; | |
-moz-transition: all 1s ease; | |
-o-transition: all 1s ease; | |
transition: all 1s ease; | |
} | |
#new span { | |
background: #fff; | |
position: absolute; | |
color: #1c8dc4; | |
padding: 4px 10px; | |
font-size: 16px; | |
font-weight: 600; | |
letter-spacing: 1px; | |
margin-top: -5px; | |
} | |
#popUp .close { | |
color: #464646; | |
right: 8px; | |
top: 0px; | |
position: absolute; | |
font-size: 20px; | |
cursor: pointer; | |
} | |
#popUp h2 { | |
font-size: 17px; | |
color: #464646; | |
line-height: 24px; | |
font-weight: 400; | |
text-align: center; | |
margin-top: 40px; | |
padding: 0 20px; | |
} | |
#body { | |
height: 1200px; | |
background: #eee; | |
} | |
a.button { | |
margin: 0 auto; | |
text-align: center; | |
right: 0; | |
left: 0; | |
position: absolute; | |
width: 120px; | |
font-size: 15px; | |
color: #fff; | |
border-bottom: 2px solid #18729f; | |
background: #1c8dc4; | |
border-radius: 4px; | |
padding: 8px 0; | |
} | |
#plus { | |
position: fixed; | |
color: #fff; | |
bottom: 15%; | |
font-size: 15px; | |
margin-left: -425px; | |
-webkit-transition: all 1.25s ease; | |
-moz-transition: all 1.25s ease; | |
-o-transition: all 1.25s ease; | |
transition: all 1.25s ease; | |
cursor: pointer; | |
text-align: left; | |
letter-spacing: 1px; | |
} | |
#plus span { | |
position: absolute; | |
margin-top: 38px; | |
left: 4px; | |
} | |
#plus::after { | |
content: ''; | |
display: block; | |
display: relative; | |
border-top: 55px solid transparent; | |
border-bottom: 55px solid transparent; | |
border-left: 55px solid #1c8dc4; | |
} | |
@media all and (max-width: 900px) { | |
#popUp { | |
margin-left: -425px; | |
} | |
#plus { | |
margin-left: 0px; | |
} | |
} |