I have a webpage which has some css that makes an image appear from the left and move in slightly to the right. However this animation is done as soon as the page is loaded so it does not appear to move at all. I would like the animation to fire when the user scrolls down to the portion of the page where the image is located. How would I go about doing this? Here is my current code for the animation:
#-webkit-keyframes move
{
from {
left: -100%;
}
to {
left: -10%;
}
}
#keyframes move
{
from {
left: -100%;
}
to {
left: -10%;
}
}
.rotator{
text-decoration: none;
padding-right: 20px;
left: -10%;
position: absolute;
-webkit-animation: move 5s;
animation: move 5s;
}
.rotator img {
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
border-radius:60px;
transition-duration: 1s;
}
and here is the html i put on the page:
<a class="rotator"><img src="img/lc.png" /></a>
Thanks in advance!
You could use JQuery to measure if the user has reached a certain point on the website. If so, then you should add a class which contains the animation.
JQuery:
$(document).scroll(function() {
if ($(document).scrollTop() == 200) {
$("#block").addClass("animate");
}
});
In the line if ($(document).scrollTop() == 200) is 200 equal to the y-coördinate of the element which should animate.
Example:
$(document).scroll(function() {
if ($(document).scrollTop() == 200) {
$("#block").addClass("animate");
}
});
body {
height: 2000px;
margin: 0px;
}
#block {
width: 120px;
height: 120px;
line-height: 120px;
text-align: center;
border: 2px solid red;
margin: 200px auto;
}
.animate {
animation: spin 4s linear infinite;
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div id="block">
Block
</div>
Your code doesn't render a animation... something is wrong there. I recommend you to find a piece of working code, and read it and adapt. For example this one, has a menu, but you can change all make it work for your purposes.
Check this example that works and re-use the code.
The menu bar slides down on page load, pure CSS.
header {
background: #666;
color: #fff;
height: 20px;
position: relative;
padding: 10px;
-moz-animation-name: dropHeader;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: ease-in;
-moz-animation-duration: 0.5s;
-webkit-animation-name: dropHeader;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-in;
-webkit-animation-duration: 0.5s;
animation-name: dropHeader;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 0.5s;
}
header ul {
list-style: none;
margin: 0;
padding: 0;
}
header ul li {
display: inline-block;
margin-right: 20px
}
header ul li a {
color: #eee;
text-decoration: none;
}
#-moz-keyframes dropHeader {
0% {
-moz-transform: translateY(-40px);
}
100% {
-moz-transform: translateY(0);
}
}
#-webkit-keyframes dropHeader {
0% {
-webkit-transform: translateY(-40px);
}
100% {
-webkit-transform: translateY(0);
}
}
#keyframes dropHeader {
0% {
transform: translateY(-40px);
}
100% {
transform: translateY(0);
}
}
/* For aesthetics only */
body {
margin: 0;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
}
.intro {
padding: 40px;
}
.intro h1 {
font: 200 1.7em Segoe UI, "Segoe UI Light", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-weight: 200;
color: #666;
}
.intro p {
max-width: 600px;
}
<header>
</header>
<div class="intro">
</div>
Related
So I want to have an image that covers the entire screen until you start scrolling down. (This image is also a slideshow with fading animation) At the center of that image should be text. A header should overlap the image and a footer should be beneath it. (I will add more content inbetween the footer and the image later)
However, currently it is not working as intended. Both the header and the footer are overlapped by the background image. The text centers right where the header and footer snap together instead of in the middle of the background image. I need some help with this. Refer to an image and code below. You may also view the page at https://www.mh-rp.com.
image with notes and clarification
<body style="background-color:#111111">
<header>
<div class="header">
<div class="inner_header">
<div class="logo_container">
<img src="/images/weblogo.png" alt="MHRP">
</div>
<ul class="navigation">
<li><i class="fa fa-home"></i> Home</li>
<li><i class="fa fa-address-card"></i> About</li>
<li><i class="fa fa-comments"></i> Forum</li>
<li><i class="fa fa-sign-in"></i> UCP</li>
<li><i class="fab fa-discord"></i> Discord</li>
</ul>
<div class="menu-toggle"><i class="fa fa-bars" aria-hidden="true"></i></div>
</div>
</div>
</header>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.menu-toggle').click(function(){
$('.navigation').toggleClass('active')
})
})
</script>
<main>
<div class="image_container">
<div id="background-preload" class="background-start"></div>
<script>$('#background-preload').delay(5000).fadeOut('slow');</script>
<ul class="cb-slideshow">
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
</ul>
<div class="maintext">Mulholland Roleplay
<div><img class="ipimage" src="/images/sa-mp.png"></div>
<div><span class="mainip">57.80.79.165:1050</span></div>
<div><a class="mainbutton" href="https://www.forum.mh-rp.com/wiki/game-server/">Play Now</a></div>
</div>
</div>
</main>
<footer>
<div class="footer">
<div class="inner_footer">
<div class="logo_container2">
<img src="/images/logo.png" alt="MHRP">
<div>
<img src ="https://images.dmca.com/Badges/dmca_protected_sml_120l.png?ID=6c4220d8-268c-4e0c-897f-3ba9a38e002d" alt="DMCA.com Protection Status" /> <script src="https://images.dmca.com/Badges/DMCABadgeHelper.min.js"> </script>
</div>
</div>
<div class="footer_third">
<h1>Need Help?</h1>
Contact Us
Cookie Usage
Terms & Conditions
Privacy Policy
</div>
<div class="footer_third">
<h1>More</h1>
Encyclopedia
Credit Store
Rockstar Games
San Andreas Multiplayer
</div>
<div class="footer_third">
<h1>Follow Us</h1>
<li><i class="fa fa-instagram"></i> Instagram</li>
<li><i class="fa fa-twitter"></i> Twitter</li>
<li><i class="fa fa-youtube"></i> YouTube</li>
</div>
<br/>
<div class="footer_third">
<p style="color:white; text-align:center; font-size:16px;"><br/><br/>Copyright © 2019 mh-rp.com
<br/>
The mh-rp game server is powered by sa-mp.com. sa-mp.com is powered by Grand Theft Auto: San Andreas.
<br/>
mh-rp.com and the contents herein, are not affiliated with Rockstar Games, Rockstar North, Take-Two Interactive Software Inc or sa-mp.com.
<br/>
Grand Theft Auto and Grand Theft Auto: San Andreas are registered trademarks of Take-Two Interactive Software Inc.</p>
</div>
</div>
</footer>
<script src="/js/cookieconsent.min.js" data-cfasync="false"></script>
<script>
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#3a3a3a",
"text": "#a0a09e"
},
"button": {
"background": "#185886"
}
},
"content": {
"message": "This site uses cookies to help personalise content, tailor your experience, advertise and to keep you logged in if you register.\nBy continuing to use this site, you are consenting to our use of cookies.",
"dismiss": "Accept",
"link": "Learn more..."
},
"position": "bottom-left"
});
</script>
</body>
#import url('https://fonts.googleapis.com/css?family=Staatliches&display=swap');
*
{
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
}
/* start of not found */
.logo_container3
{
text-align: center;
}
.headertext
{
color: white;
display: block;
text-align: center;
width: 100%;
padding-top: 20px;
}
.buttontext
{
color: white;
font-family: "Verdana";
padding: 0px 20px;
}
.buttontext:hover
{
color:white; background:#292929;
-o-transition:color .2s ease-out, background 0.5s ease-in;
-ms-transition:color .2s ease-out, background 0.5s ease-in;
-moz-transition:color .2s ease-out, background 0.5s ease-in;
-webkit-transition:color .2s ease-out, background 0.5s ease-in;
/* ...and now override with proper CSS property */
transition:color .2s ease-out, background 0.5s ease-in;
background-color: #185886;
}
/* end of not found */
/* start of header */
.header
{
width: 100%;
height: 80px;
display: block;
background-color: #292929;
}
.inner_header
{
width: 1000px;
height: 100%;
display: block;
margin: 0 auto;
background-color: #292929;
}
.logo_container
{
height: 100%;
display: table;
float: left;
}
.logo_container img
{
display: table-cell;
vertical-align: middle;
padding-top: 5%;
height:60px
}
.navigation
{
float: right;
height: 100%;
}
.navigation a
{
height: 100%;
display: table;
float: left;
padding: 0px 20px;
}
.navigation a li
{
display: table-cell;
vertical-align: middle;
height: 100%;
color: white;
font-family: "Verdana";
font-size: 16px;
}
.navigation a:first-child
{
background-color: #185886;
}
.navigation a:hover
{
color:white; background:#292929;
-o-transition:color .2s ease-out, background 0.5s ease-in;
-ms-transition:color .2s ease-out, background 0.5s ease-in;
-moz-transition:color .2s ease-out, background 0.5s ease-in;
-webkit-transition:color .2s ease-out, background 0.5s ease-in;
/* ...and now override with proper CSS property */
transition:color .2s ease-out, background 0.5s ease-in;
background-color: #185886;
}
/* mobile */
.menu-toggle
{
color: white;
float:right;
line-height: 77px;
font-size: 48px;
cursor: pointer;
display: none;
}
#media (max-width: 1000px)
{
.menu-toggle
{
display: block;
}
.navigation
{
position: absolute;
width: 100%;
height: calc(100vh -50px);
background: #333;
top: 80px;
left: -100%;
transition: 0.5s;
display: grid;
}
.navigation.active
{
left: 0;
}
.navigation ul
{
display: block;
text-align: center;
}
.navigation ul li a
{
border-bottom: 1px solid rgba(0,0,0,.2);
}
.inner_header
{
width: 90%;
}
}
/* end of header */
/* start of footer */
.footer
{
width: 100vw;
display: block;
overflow: hidden;
padding: 70px 0;
box-sizing: border-box;
background-color: #18181a;
}
.inner_footer
{
display: block;
margin: 0 auto;
width: 1100px;
height: 100%;
}
.inner_footer .logo_container2
{
width:35%;
float: left;
height: 100%;
display: block;
}
.inner_footer .logo_container2 img
{
width: 100px;
height: auto;
}
.inner_footer .footer_third
{
width: calc(21.6666666667% -20px);
margin-right: 10px;
float: left;
height: 100%;
}
.inner_footer .footer_third:last-child
{
margin-right: 0;
}
.inner_footer .footer_third h1
{
font-family: 'arial';
font-size: 22px;
color: white;
display: block;
width: 100%;
margin-bottom: 20px;
}
.inner_footer .footer_third a
{
font-family: "Arial";
font-size: 18px;
color: white;
display: block;
font-weight: 200;
width: 100%;
}
.inner_footer .footer_third a:hover
{
color:white; background:#292929;
-o-transition:color .2s ease-out, background 0.5s ease-in;
-ms-transition:color .2s ease-out, background 0.5s ease-in;
-moz-transition:color .2s ease-out, background 0.5s ease-in;
-webkit-transition:color .2s ease-out, background 0.5s ease-in;
/* ...and now override with proper CSS property */
transition:color .2s ease-out, background 0.5s ease-in;
background-color: #185886;
}
/* mobile */
#media(max-width: 1000px)
{
.footer .inner_footer
{
width: 90%;
}
.inner_footer .logo_Container2,
.inner_footer .footer_third
{
width: 100%;
margin-bottom: 30px;
}
}
/* end of footer */
/* start of main */
body
{
overflow-x: hidden;
}
/* this is there to show no fading animation when you load the page for the first time */
.background-start
{
background-image: url(../images/1.png);
position: fixed;
background-attachment: fixed;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background-size: cover;
background-position: 50% 50%;
background-repeat: none;
}
.cb-slideshow,
.cb-slideshow:after {
position: fixed;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
z-index: 0;
}
.cb-slideshow li span {
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
color: transparent;
background-size: cover;
background-position: 50% 50%;
background-repeat: none;
background-attachment: fixed;
opacity: 0;
z-index: 0;
-webkit-backface-visibility: hidden;
-webkit-animation: imageAnimation 36s linear infinite 0s;
-moz-animation: imageAnimation 36s linear infinite 0s;
-o-animation: imageAnimation 36s linear infinite 0s;
-ms-animation: imageAnimation 36s linear infinite 0s;
animation: imageAnimation 36s linear infinite 0s;
}
.cb-slideshow li:nth-child(1) span {
background-image: url(../images/1.png);
}
.cb-slideshow li:nth-child(2) span {
background-image: url(../images/2.png);
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-o-animation-delay: 6s;
-ms-animation-delay: 6s;
animation-delay: 6s;
}
.cb-slideshow li:nth-child(3) span {
background-image: url(../images/3.png);
-webkit-animation-delay: 12s;
-moz-animation-delay: 12s;
-o-animation-delay: 12s;
-ms-animation-delay: 12s;
animation-delay: 12s;
}
.cb-slideshow li:nth-child(4) span {
background-image: url(../images/4.png);
-webkit-animation-delay: 18s;
-moz-animation-delay: 18s;
-o-animation-delay: 18s;
-ms-animation-delay: 18s;
animation-delay: 18s;
}
.cb-slideshow li:nth-child(5) span {
background-image: url(../images/5.png);
-webkit-animation-delay: 24s;
-moz-animation-delay: 24s;
-o-animation-delay: 24s;
-ms-animation-delay: 24s;
animation-delay: 24s;
}
.cb-slideshow li:nth-child(6) span {
background-image: url(../images/6.png);
-webkit-animation-delay: 30s;
-moz-animation-delay: 30s;
-o-animation-delay: 30s;
-ms-animation-delay: 30s;
animation-delay: 30s;
}
/* Animation for the slideshow images */
#-webkit-keyframes imageAnimation {
0% { opacity: 0;
-webkit-animation-timing-function: ease-in; }
8% { opacity: 1;
-webkit-animation-timing-function: ease-out; }
17% { opacity: 1 }
25% { opacity: 0 }
100% { opacity: 0 }
}
#-moz-keyframes imageAnimation {
0% { opacity: 0;
-moz-animation-timing-function: ease-in; }
8% { opacity: 1;
-moz-animation-timing-function: ease-out; }
17% { opacity: 1 }
25% { opacity: 0 }
100% { opacity: 0 }
}
#-o-keyframes imageAnimation {
0% { opacity: 0;
-o-animation-timing-function: ease-in; }
8% { opacity: 1;
-o-animation-timing-function: ease-out; }
17% { opacity: 1 }
25% { opacity: 0 }
100% { opacity: 0 }
}
#-ms-keyframes imageAnimation {
0% { opacity: 0;
-ms-animation-timing-function: ease-in; }
8% { opacity: 1;
-ms-animation-timing-function: ease-out; }
17% { opacity: 1 }
25% { opacity: 0 }
100% { opacity: 0 }
}
#keyframes imageAnimation {
0% { opacity: 0;
animation-timing-function: ease-in; }
8% { opacity: 1;
animation-timing-function: ease-out; }
17% { opacity: 1 }
25% { opacity: 0 }
100% { opacity: 0 }
}
/* Show at least something when animations not supported */
.no-cssanimations .cb-slideshow li span{
opacity: 1;
}
#media screen and (max-width: 1140px) {
.cb-slideshow li div h3 { font-size: 140px }
}
#media screen and (max-width: 600px) {
.cb-slideshow li div h3 { font-size: 80px }
}
.image_container
{
position:relative;
}
.maintext
{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-family: "Staatliches", "Arial", sans-serif;
font-weight:normal;
font-style:normal;
font-size: 72px;
}
.mainbutton
{
position: absolute;
top: 150%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-family: "Staatliches", "Arial", sans-serif;
font-weight:normal;
font-style:normal;
font-size: 32px;
border-style: solid;
border-width: 1px;
border-color: white;
transition: border-width 0.3s;
padding: 5px 5px 5px 5px;
}
.mainip
{
position: absolute;
top: 100%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-family: "Staatliches", "Arial", sans-serif;
font-weight:normal;
font-style:normal;
font-size: 32px;
}
.ipimage
{
position: absolute;
top: 80%;
left: 27.5%;
width: 32px;
}
.mainbutton:hover
{
border-width: 3px;
}
/* end of main */
Add those two selectors.
.image-container { height: 100vh }
header, footer { position: relative; z-index: 1 }
been working and learning to build this page for about 4-5 hours and I cannot seem to find out why I am unable to get the navigation links on the same line as the navbar-logo and secondly is there any way I could make this code more efficient and less dependent/error-prone?
One more thing I wanted to ask is can we use flexbox in this webpage? and is CSS animation used is efficient here?
body{
background-color: #000;
color: #f1f1f1;
animation: fade-in 2s 1;
}
header{
width: 100%;
height: 10%;
margin: auto;
}
.navbar-logo{
padding: 2px 0px 2px 100px;
position: absolute;
z-index: 100;
}
.navbar-logo-sub{
padding: 55px 0px 0px 200px;
}
#logo-main{
font-family: 'Didact Gothic', sans-serif;
color: white;
font-size: 40px;
font-weight: 800;
margin: 0;
}
.parenthesis1{
color: #b22121;
font-family: 'Bungee', cursive;
}
.parenthesis2{
color: #787878;
font-family: 'Bungee', cursive;
}
#logo-sub{
color: white;
font-size: 14px;
font-weight: 20;
font-family: 'Coming Soon', cursive;
}
#banner-image{
width: 50%;
padding-left: 20%;
filter: blur(3px);
position: relative;
padding-top: 5%;
}
#banner-text{
top: 50%;
left: 50%;
position: fixed;
transform: translate(-50%, -50%);
font-size: 50px;
text-align: left;
}
nav{
padding: 0px 0px 0px 60%;
}
li{
float: left;
margin-right: 100px;
list-style-type: none;
}
a{
text-decoration: none;
color: white;
}
h1{
margin-top: 0px;
margin-bottom: -50px;
font-family: 'Permanent Marker', cursive;
font-weight: 300;
text-shadow: 4px 2px rgba(238, 238, 238, 0.5);
opacity: 0;
-webkit-animation: slide-in 3s 1 forwards;
}
div h1:nth-of-type(2){
animation-delay: 0.1s;
-webkit-animation-delay: 0.1s;
}
div h1:nth-of-type(3){
animation-delay: 0.2s;
-webkit-animation-delay: 0.2s;
}
div h1:nth-of-type(4){
animation-delay: 0.3s;
-webkit-animation-delay: 0.3s;
}
div h1:nth-of-type(5){
animation-delay: 0.4s;
-webkit-animation-delay: 0.4s;
}
div h1:nth-of-type(6){
animation-delay: 0.5s;
-webkit-animation-delay: 0.5s;
}
div h1:nth-of-type(7){
animation-delay: 0.6s;
-webkit-animation-delay: 0.6s;
}
div h1:nth-of-type(8){
animation-delay: 0.7s;
-webkit-animation-delay: 0.7s;
}
div h1:nth-of-type(9){
animation-delay: 0.8s;
-webkit-animation-delay: 0.8s;
}
#keyframes slide-in {
0%{
transform: rotateY(90deg) translateY(-50%);
opacity: 0.0;
}
100%{
transform: rotateY(0deg) translateY(0%);
opacity: 1.0;
}
}
#-webkit-keyframes slide-in {
0%{
-webkit-transform: rotateY(90deg) translateY(25%);
opacity: 0.0;
}
100%{
-webkit-transform: rotateY(0deg) translateY(0%);
opacity: 1.0;
}
}
#keyframes fade-in {
0%{
opacity: 0.0;
}
50%{
opacity: 0.5;
}
100%{
opacity: 1.0;
}
<html>
<head>
<title>.whatsthecode.</title>
<link rel="stylesheet" href="index.css">
<link href="https://fonts.googleapis.com/css?
family=Didact+Gothic|Coming+Soon|Bungee|Permanent+Marker" rel="stylesheet">
</head>
<body>
<header>
<div class="navbar-logo">
<p id="logo-main">WhatsTheCode<span class="parenthesis1">(</span>
<span class="parenthesis2">)</span></p>
</div>
<div class="navbar-logo-sub"><p id="logo-sub">{<html><span style="color: #b22121"><style></span><span style="color: #787878"><script></span>}</p></div>
<nav>
<ul>
<li>Home</li>
<li>FAQ</li>
<li>About</li>
</ul>
</nav>
</header>
<section>
<div class="banner">
<img src="banner-background.png" id="banner-image">
<div id="banner-text"><h1>Your</h1><h1>web development</h1>
<h1>develops</h1><h1>here.</h1></div>
</div>
</section>
</body>
</html>
Here you go brother, I added a div with class="navbar-wrapper" and placed the header elements inside it. I used the display:inline-block on the header elements so that they are horizontally aligned. For the navbar-logo-sub, I placed it inside the navbar-logo and used position:absolute, and bottom:0 to place it at the bottom of the parent element. Run Code snippet and view it on full page.
body {
background-color: #000;
color: #f1f1f1;
animation: fade-in 2s 1;
}
header {
width: 100%;
}
.navbar-wrapper{
padding-left:50px; padding-right:50px;
}
header .navbar-logo {
display: inline-block;
position: relative;
}
header nav {
display: inline-block;
}
header .navbar-logo-sub {
display: block;
position: absolute;
bottom: 0;
left: 20%;
}
nav {
padding: 0px;
margin: 0px;
}
header li {
float: left;
margin-right: 50px;
list-style-type: none;
}
header li:last-of-type {
margin-right: 0px;
}
a {
text-decoration: none;
color: white;
}
#logo-main {
font-family: 'Didact Gothic', sans-serif;
color: white;
font-size: 2.3em;
font-weight: 800;
margin: 0;
}
.parenthesis1 {
color: #b22121;
font-family: 'Bungee', cursive;
}
.parenthesis2 {
color: #787878;
font-family: 'Bungee', cursive;
}
#logo-sub {
color: white;
font-size: 14px;
font-weight: 20;
font-family: 'Coming Soon', cursive;
}
#banner-image {
width: 50%;
padding-left: 20%;
filter: blur(3px);
position: relative;
padding-top: 5%;
}
#banner-text {
top: 50%;
left: 50%;
position: fixed;
transform: translate(-50%, -50%);
font-size: 50px;
text-align: left;
}
h1 {
margin-top: 0px;
margin-bottom: -50px;
font-family: 'Permanent Marker', cursive;
font-weight: 300;
text-shadow: 4px 2px rgba(238, 238, 238, 0.5);
opacity: 0;
-webkit-animation: slide-in 3s 1 forwards;
}
div h1:nth-of-type(2) {
animation-delay: 0.1s;
-webkit-animation-delay: 0.1s;
}
div h1:nth-of-type(3) {
animation-delay: 0.2s;
-webkit-animation-delay: 0.2s;
}
div h1:nth-of-type(4) {
animation-delay: 0.3s;
-webkit-animation-delay: 0.3s;
}
div h1:nth-of-type(5) {
animation-delay: 0.4s;
-webkit-animation-delay: 0.4s;
}
div h1:nth-of-type(6) {
animation-delay: 0.5s;
-webkit-animation-delay: 0.5s;
}
div h1:nth-of-type(7) {
animation-delay: 0.6s;
-webkit-animation-delay: 0.6s;
}
div h1:nth-of-type(8) {
animation-delay: 0.7s;
-webkit-animation-delay: 0.7s;
}
div h1:nth-of-type(9) {
animation-delay: 0.8s;
-webkit-animation-delay: 0.8s;
}
#keyframes slide-in {
0% {
transform: rotateY(90deg) translateY(-50%);
opacity: 0.0;
}
100% {
transform: rotateY(0deg) translateY(0%);
opacity: 1.0;
}
}
#-webkit-keyframes slide-in {
0% {
-webkit-transform: rotateY(90deg) translateY(25%);
opacity: 0.0;
}
100% {
-webkit-transform: rotateY(0deg) translateY(0%);
opacity: 1.0;
}
}
#keyframes fade-in {
0% {
opacity: 0.0;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1.0;
}
<html>
<head>
<title>.whatsthecode.</title>
<link href="https://fonts.googleapis.com/css?
family=Didact+Gothic|Coming+Soon|Bungee|Permanent+Marker" rel="stylesheet">
</head>
<body>
<header>
<div class="navbar-wrapper">
<div class="navbar-logo">
<p id="logo-main">WhatsTheCode<span class="parenthesis1">(</span>
<span class="parenthesis2">)</span></p>
<div class="navbar-logo-sub">
<p id="logo-sub">{<html><span style="color: #b22121"><style></span><span style="color:
#787878"><script></span>}</p>
</div>
</div>
<nav>
<ul>
<li>Home</li>
<li>FAQ</li>
<li>About</li>
</ul>
</nav>
</div>
</header>
<section>
<div class="banner">
<img src="banner-background.png" id="banner-image">
<div id="banner-text">
<h1>Your</h1>
<h1>web development</h1>
<h1>develops</h1>
<h1>here.</h1>
</div>
</div>
</section>
</body>
</html>
I have created a anchor link button where I want to show Spinner animation when I click on button in :focus state. I'm using Font Awesome to show animation but when I click on the button, the spinner animation is not working.
Note: I don't want to use JavaScript here just want to do with Pure
CSS
Here is the CodePen link https://codepen.io/rhulkashyap/pen/vLPNdQ
#import url(https://fonts.googleapis.com/css?family=Titillium+Web);
body {
font-family: 'Titillium Web', sans-serif;
text-align: center;
}
#button {
padding: 15px;
background-color: green;
color: #fff;
text-decoration: none;
border-radius: 5px;
width: 300px;
display: inline-block;
text-align: center;
font-size: 25px;
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
#button:before {
content: "\f090";
font-family: FontAwesome;
margin-right: 5px;
}
#button:focus {
background-color: #02b402;
}
#button:focus:before {
content: "\f1ce";
-webkit-animation: spin .8s ease infinite;
animation: spin .8s ease infinite;
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
#keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<h2> Click Here</h2>
<a id="button" href="javascript:void(0)">Enter In</a>
Transforms are supposed to work only on block level elements (including inline-block). Making the pseudo-element as display:inline-block makes the animation work.
After commenting on the question, I did see that the animation wasn't working in Chrome v50 (dev-m) also while it was working in Chrome v43. So, the current behavior seems to be consistent
#import url(https://fonts.googleapis.com/css?family=Titillium+Web);
body {
font-family: 'Titillium Web', sans-serif;
text-align: center;
}
#button {
padding: 15px;
background-color: green;
color: #fff;
text-decoration: none;
border-radius: 5px;
width: 300px;
display: inline-block;
text-align: center;
font-size: 25px;
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
#button:before {
display: inline-block;
content: "\f090";
font-family: FontAwesome;
margin-right: 5px;
}
#button:focus {
background-color: #02b402;
}
#button:focus:before {
content: "\f1ce";
-webkit-animation: spin .8s ease infinite;
animation: spin .8s ease infinite;
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
#keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<h2> Click Here</h2>
<a id="button" href="javascript:void(0)">Enter In</a>
I got this banner thingy from a tutorial, but the thing is, instead of the banner continuing in loops, it resets instead. I don't want to use any javascript since we we're not yet tackling it in uni. Can anyone point out where I did wrong and how to fix it? Thanks.
Here are the images:
[1]
[2]
and this is the code I used
HTML:
<div class="photobanner">
<img class="first" src="images/scroll/ban.jpg" style="width:350px;height:233px;"/>
<img src="images/scroll/banner1.png" style="width:350px;height:233px;"/>
<img src="images/scroll/banner3.jpg" style="width:350px;height:233px;"/>
<img src="images/scroll/banner4.jpg" style="width:350px;height:233px;"/>
<img src="images/scroll/banner5.jpg" style="width:350px;height:233px;"/>
</div>
</div>
CSS:
/*body and container*/
* {
margin: 0;
padding: 0;
}
body {
background-image:url(images/banner1takuya.jpg);
background-size: cover;
background-attachment: fixed;
}
#container {
width:865px;
height:auto;
margin:auto;
padding:0 0 30px 0;
background-image:url(images/bg.png);
}
/*header*/
header {
width: 800px;
margin: 40px auto;
}
header h1 {
text-align: center;
font: 100 60px/1.5 Helvetica, Verdana, sans-serif;
}
header p {
font: 100 15px/1.5 Helvetica, Verdana, sans-serif;
text-align: justify;
}
/*photobanner*/
.photobanner {
height: 233px;
width: 3550px;
margin-bottom: 80px;
}
.photobanner img {
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.photobanner img:hover {
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-o-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
cursor: pointer;
-webkit-box-shadow: 0px 3px 5px rgba(0,0,0,0.2);
-moz-box-shadow: 0px 3px 5px rgba(0,0,0,0.2);
box-shadow: 0px 3px 5px rgba(0,0,0,0.2);
}
/*keyframe animations*/
.first {
-webkit-animation: bannermove 30s linear infinite;
-moz-animation: bannermove 30s linear infinite;
-ms-animation: bannermove 30s linear infinite;
animation: bannermove 30s linear infinite;
}
#keyframes "bannermove" {
0% {
margin-left: 0px;
}
100% {
margin-left: -2125px;
}
}
#-moz-keyframes bannermove {
0% {
margin-left: 0px;
}
100% {
margin-left: -2125px;
}
}
#-webkit-keyframes "bannermove" {
0% {
margin-left: 0px;
}
100% {
margin-left: -2125px;
}
}
#-ms-keyframes "bannermove" {
0% {
margin-left: 0px;
}
100% {
margin-left: -2125px;
}
}
#-o-keyframes "bannermove" {
0% {
margin-left: 0px;
}
100% {
margin-left: -2125px;
}
}
You have the .photobanner width set to 3550px, but the sum of images' widths is 355*5=1775px only.
You need to add 5 more images of the same size and this will work correctly.
I have implemented a CSS3 Animation for a Div-Element which has Header text and "Read more"-link. I'm using translateX function to animate the container from left to right of the screen.
The problem is that the "Read more"-link which has an anchor goes to unclickable while the box animation. But when the animation ends the anchor becomes clickable.
Can anyone help me finding the problem behind this?
HTML
<div>
<h3>Title1</h3>
<p class="sub-text">Title1 Desc </p>
<p class="read-more">Read More</p>
</div>
CSS
div {
z-index: 1000;
position: absolute;
bottom: 30px;
left: 27%;
width: 62%;
text-align: left;
background: rgba(0,0,0, 0.6) none repeat scroll 0 0;
opacity: 0;
-webkit-animation: titleAnimation 36s linear infinite 0s;
-moz-animation: titleAnimation 36s linear infinite 0s;
-o-animation: titleAnimation 36s linear infinite 0s;
-ms-animation: titleAnimation 36s linear infinite 0s;
animation: titleAnimation 36s linear infinite 0s;
}
div h3 {
font-family: 'Roboto', sans-serif;
font-size: 3em;
padding: 0 25px;
margin: 30px 0px 5px 0px;
color: rgba(255,255,255,0.8);
}
div p.sub-text {
font-family: 'Roboto', sans-serif;
font-size: 1.2em;
padding: 5px 25px;
color: rgba(255,255,255,0.6);
margin: 0px;
}
div p.read-more {
font-family: 'Roboto', sans-serif;
font-size: 0.8em;
padding: 10px 25px 20px;
}
div p.read-more a {
padding: 10px 10px 10px 20px;
display: inline-block;
background: rgb(223, 75, 20);
text-decoration: none;
color: rgba(255,255,255,0.6);
margin: 0px;
font-weight: 700;
}
titleAnimation {
0% {
opacity: 0;
-webkit-transform: translateX(300%);
}
8% {
opacity: 1;
-webkit-transform: translateX(10%);
}
17% {
opacity: 1;
-webkit-transform: translateX(5%);
}
19% {
opacity: 0;
-webkit-transform: translateX(-10%);
}
25% { opacity: 0 }
100% { opacity: 0 }
}
Working Sample is
http://jsfiddle.net/a4enq/
Why would you want to try and click the link whilst its moving?
Anyway, I believe that this is the default browser behavior (Chrome) because when you are using translate(X,Y,Z,3d) it creates a new layer of the elements moving and repaints the element you're moving and make everything position: relative and disables all anchors until the animation has stopped.
You could use margins or left position for the animation (so at to manipulate the DOM and not the renderer)
This way it will work but it will lose hardware accelerated benefits
http://jsfiddle.net/L5tv8/1/
#keyframes titleAnimation {
0% {
opacity: 0;
margin-left:300%;
}
8% {
opacity: 1;
margin-left:10%;
}
17% {
opacity: 1;
margin-left:5%;
}
19% {
opacity: 0;
margin-left:-10%;
}
25% { opacity: 1 }
100% { opacity: 1 }
}