Skip to content

Instantly share code, notes, and snippets.

@CodeMyUI
Created March 21, 2017 04:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CodeMyUI/a442de2e7fdb62600de28d51348dbe08 to your computer and use it in GitHub Desktop.
Save CodeMyUI/a442de2e7fdb62600de28d51348dbe08 to your computer and use it in GitHub Desktop.
Preloading animation with velocity.js and CSS3 transitions
<!-- Page preloader -->
<div id="hola">
<div id="preloader">
<span></span>
<span></span>
</div>
</div>
<!-- Start content -->
<div class="page-wrap">
<div class="home">
<div class="text-wrap">
<h1>So the tale continues</h1>
<p>
Though, consumed with the hot fire of his purpose, Ahab in all his thoughts and actions ever had in view the ultimate capture of Moby Dick; though he seemed ready to sacrifice all mortal interests to that one passion; nevertheless it may have been that he was by nature and long habituation far too wedded to a fiery whaleman's ways, altogether to abandon the collateral prosecution of the voyage. Or at least if this were otherwise, there were not wanting other motives much more influential with him. It would be refining too much, perhaps, even considering his monomania, to hint that his vindictiveness towards the White Whale might have possibly extended itself in some degree to all sperm whales, and that the more monsters he slew by so much the more he multiplied the chances that each subsequently encountered whale would prove to be the hated one he hunted.
</p>
</div>
</div>
</div>

Preloading animation with velocity.js and CSS3 transitions

Just a preloading animation, didn't saw much of them here on Codepen, so I was thinking why not create one ?

Used jQuery's window.load() function, in this demo there is also setTimeot() used, cause there is no content to load, so we are simulating it.

A Pen by Mirko Zorić on CodePen.

License.

$(window).load(function(){
setTimeout(function(){
$('#preloader').velocity({
opacity : 0.1,
translateY: "-80px"
}, {
duration: 400,
complete: function(){
$('#hola').velocity({
translateY : "-100%"
}, {
duration: 1000,
easing: [0.7,0,0.3,1],
complete: function(){
$('.home').addClass('animate-border divide');
}
})
}
})
},1000)
})
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.2.3/velocity.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.2.3/velocity.ui.min.js"></script>
/*
Just a preloading animation, didn't saw many of them here on Codepen, so I said why not create one ?
Used jQuery's window.load() function, in this demo there is also setTimeot(), cause there is no content to load, so we are simulating it.
*/
@import url(https://fonts.googleapis.com/css?family=Oswald|Josefin+Sans:300);
html {
box-sizing: border-box;
font-size: 100%;
}
*, *:before, *:after {
box-sizing: inherit;
}
/* ==== Preloader styles ==== */
#hola{
width: 100vw;
height: 100vh;
background-color: #252328;
position: fixed;
z-index: 999;
}
#preloader {
position:relative;
width: 80px;
height: 80px;
top: 45%;
margin: 0 auto;
}
#preloader span {
position:absolute;
border: 8px solid #ffe066;
border-top: 8px solid transparent;
border-radius:999px;
}
#preloader span:nth-child(1){
width:80px;
height:80px;
animation: spin-1 2s infinite linear;
}
#preloader span:nth-child(2){
top: 20px;
left: 20px;
width:40px;
height:40px;
animation: spin-2 1s infinite linear;
}
@keyframes spin-1 {
0% {transform: rotate(360deg); opacity: 1;}
50% {transform: rotate(180deg); opacity: 0.5;}
100% {transform: rotate(0deg); opacity: 1;}
}
@keyframes spin-2 {
0% {transform: rotate(0deg); opacity: 0.5;}
50% {transform: rotate(180deg); opacity: 1;}
100% {transform: rotate(360deg); opacity: 0.5;}
}
/* ==== Page layout ==== */
.page-wrap{
overflow-x: hidden;
height: 100vh;
}
.home{
height: 100vh;
position: relative;
background-color: #F2F6F2;
display: flex;
justify-content: center;
align-items: center;
}
.home:before{
position: absolute;
width: 50%;
height: 100%;
z-index: 10;
top: 0;
left: 0;
content: '';
background-color: #F2F6F2;
}
.home:after{
position: absolute;
width: 50%;
height: 100%;
z-index: 10;
top: 0;
right: 0;
content: '';
background-color: #F2F6F2;
}
.animate-border{
border: 40px solid #EDEBE6;
transition: border .5s .2s ease;
}
.home.divide:before{
transition: all .6s 1.2s cubic-bezier(0.645, 0.045, 0.355, 1.000);
width: 0;
}
.home.divide:after{
transition: all .6s 1.2s cubic-bezier(0.645, 0.045, 0.355, 1.000);
width: 0;
}
.text-wrap{
width: 100%;
max-width: 44rem;
text-align: center;
}
h1{
font-size: 4rem;
text-transform: uppercase;
letter-spacing: 2px;
font-weight: 700;
font-family: 'Oswald';
color: #5F5264;
margin-bottom: 3rem;
}
p{
font-size: 1rem;
color: #b6ccb6;
line-height: 1.4;
font-family: 'Josefin Sans';
}
@media screen and (max-width:1024px){
html{
font-size: 92.5%;
}
}
@media screen and (max-width:640px){
html{
font-size: 86%;
}
p{
font-size: 1.1rem;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment