On my little testing html page, I have 4 elements. These elements play a CSS animation when hovered over, but I would like the animation to go reverse when the user stops hovering over them.
-webkit-animation-direction:alternate;
didn't work. My current code is as follows:
<style>
div:hover{
-webkit-animation: animationFrames ease 1s;
-webkit-animation-iteration-count: 1;
-webkit-transform-origin: 0% 0%;
-webkit-animation-fill-mode:forwards; /*Chrome 16+, Safari 4+*/
-webkit-animation-direction:alternate;
}
#-webkit-keyframes animationFrames {
0% {
opacity:1;
-webkit-transform: rotate(0deg) scaleX(1) scaleY(1) ;
}
20% {
-webkit-transform: rotate(60deg) ;
}
40% {
-webkit-transform: rotate(40deg) ;
}
60% {
-webkit-transform: rotate(54deg) ;
}
80% {
-webkit-transform: rotate(42deg) ;
}
100% {
opacity:1;
-webkit-transform: rotate(46deg) scaleX(1) scaleY(1) ;
}
}
.testje1
{
background: black;
width:48px;
height:20px;
position:absolute;
left:200px;
top:200px;
}
.testje2
{
background: black;
width:48px;
height:20px;
position:absolute;
left:300px;
top:200px;
}
.testje3
{
background: black;
width:48px;
height:20px;
position:absolute;
left:400px;
top:200px;
}
.testje4
{
background: black;
width:48px;
height:20px;
position:absolute;
left:500px;
top:200px;
}
p
{
position:absolute;
top:-14;
left:2;
color:white;
}
</style>
<a href="http://www.redrumbureau.com" target="_blank" >
<div class="testje1"><p>home</p></div>
</a>
<a href="http://www.redrumbureau.com/work" target="_blank">
<div class="testje2"><p>home</p></div>
</a>
<a href="http://www.redrumbureau.com/clients" target="_blank">
<div class="testje3"><p>clients</p></div>
</a>
<a href="http://www.redrumbureau.com/about" target="_blank">
<div class="testje4"><p>about</p></div>
</a>
All help greatly appreciated!
Use reverse to make the animation go "backwards":
-webkit-animation-direction:reverse;
Here's a nice detailed tutorial on keyframes by CSS tricks if you'd like to learn more about the options available to you.
Related
.box1{
width:200px;
height:200px;
background-color: #FFF8DC;
position:absolute;
top:200px;
left:20%;
margin-left:-100px;
}
.box1.hover {
-webkit-animation: moving-image 2s 1;
}
#-webkit-keyframes moving-image {
from { -webkit-transform: rotate(0deg) scale(1);
}
to { -webkit-transform: rotate(360deg) scale(1.3);}
}
<div class='box1'></div>
When you hover over a box I want it to increase its size and rotate it 360 degrees once. When you remove the cursor from the box I want it to go back to its original shape. I have put my code below and I don't know what's wrong with it.
.box1{
width:200px;
height:200px;
background-color: #FFF8DC;
position:absolute;
top:200px;
left:20%;
margin-left:-100px;
}
#-webkit-keyframes moving-image {
from { -webkit-transform: rotate(0deg) scale(1);
}
to { -webkit-transform: rotate(360deg) scale(1.3);}
}
.box1.hover {
-webkit-animation: moving-image 2s 1;
}
I think I have what you're looking for:
There is no need for webkit keyframes & all of that stuff. All I did was add a :hover effect and a css transition (which makes the spin effect)
.box1{
width:200px;
height:200px;
background-color: red;
position:absolute;
top:200px;
left:20%;
margin-left:-100px;
transition: all ease 1s;
}
.box1:hover{
transform: rotate(360deg) scale(1.3);
}
<div class="box1"></div>
Edit:
Your version would've worked fine as well if you change the
.box1.hover {
-webkit-animation: moving-image 2s 1;
}
to
.box1:hover {
-webkit-animation: moving-image 2s 1;
}
Both can be done with transform, like so:
.myClass {
transform: scale(1.3) rotate(360deg);
}
but to be on the safe side, you should take care of older browsers:
.myClass {
-moz-transform: scale(1.3) rotate(360deg);
-webkit-transform: scale(1.3) rotate(360deg);
-o-transform: scale(1.3) rotate(360deg);
-ms-transform: scale(1.3) rotate(360deg);
transform: scale(1.3) rotate(360deg);
}
The last line should be the standard css3 directive.
When testing my landing page on mobile view, there are weird spaces on each side of the image that allows the user to scroll and see white space. How can this be fixed? I just want it to collapse and look nice as one image with text on it on mobile view. Thanks. I want it to look like this tutorial But I keep getting white space on the sides.
*{
margin:0;
padding:0;
}
.fade-in{
animation: animationFrames ease 1s;
animation-iteration-count: 1;
transform-origin: 50% 50%;
animation-fill-mode:forwards; /*when the spec is finished*/
-webkit-animation: animationFrames ease 1s;
-webkit-animation-iteration-count: 1;
-webkit-transform-origin: 50% 50%;
-webkit-animation-fill-mode:forwards; /*Chrome 16+, Safari 4+*/
-moz-animation: animationFrames ease 1s;
-moz-animation-iteration-count: 1;
-moz-transform-origin: 50% 50%;
-moz-animation-fill-mode:forwards; /*FF 5+*/
-o-animation: animationFrames ease 1s;
-o-animation-iteration-count: 1;
-o-transform-origin: 50% 50%;
-o-animation-fill-mode:forwards; /*Not implemented yet*/
-ms-animation: animationFrames ease 1s;
-ms-animation-iteration-count: 1;
-ms-transform-origin: 50% 50%;
-ms-animation-fill-mode:forwards; /*IE 10+*/
}
#keyframes animationFrames{
0% {
opacity:0;
transform: translate(0px,-25px) ;
}
100% {
opacity:1;
transform: translate(0px,0px) ;
}
}
#-moz-keyframes animationFrames{
0% {
opacity:0;
-moz-transform: translate(0px,-25px) ;
}
100% {
opacity:1;
-moz-transform: translate(0px,0px) ;
}
}
#-webkit-keyframes animationFrames {
0% {
opacity:0;
-webkit-transform: translate(0px,-25px) ;
}
100% {
opacity:1;
-webkit-transform: translate(0px,0px) ;
}
}
#-o-keyframes animationFrames {
0% {
opacity:0;
-o-transform: translate(0px,-25px) ;
}
100% {
opacity:1;
-o-transform: translate(0px,0px) ;
}
}
#-ms-keyframes animationFrames {
0% {
opacity:0;
-ms-transform: translate(0px,-25px) ;
}
100% {
opacity:1;
-ms-transform: translate(0px,0px) ;
}
}
#showcase{
background-image:url('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS8Ilf-i2TXplUrTBJ-ugwuyd8X8mxhgMD44UQOvcawkbXx2IzNKBLWVrLA');
background-size:cover;
background-position:center;
height:100vh;
display:flex;
flex-direction:column;
justify-content:center;
align-items:center;
text-align:center;
padding: 0 20px;
}
#showcase h1{
font-size:50px;
line-height:1.2;
color:#fff;
font-family: montserrat;
letter-spacing: 10px;
}
#showcase h2{
font-size:25px;
line-height:1.2;
color:#fff;
font-family: montserrat;
}
#showcase .button{
font-size:18px;
text-decoration:none;
color:darkgreen;
padding: 10px 20px;
border-radius:10px;
margin-top:20px
}
#showcase .button:hover{
background-color: darkgreen;
color:#fff;
}
#logo {
z-index: 1;
position: absolute;
float: left;
height: 30px;
padding: 7px;
}/*effects the post logo in the top left of the page*/
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="wrapper">
<div class="wrapper fade-in">
<header id="showcase">
<h1>TITLE HERE</h1>
<h2>2017</h2>
<i class="fa fa-angle-double-right" style="font-size:36px"></i>
</header>
</div>
</div>
</body>
This is my landing page header css for background and haven't had any issues with it on mobile or desktop:
header {
position: relative;
width: 100%;
overflow-y: hidden;
/* fallback for old browsers */
background-image: url("../img/sample.jpg");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position: 50% 0;
}
Hope this helps.
I want to animate this arrow but for some reason it is not in line with the text. could you help me please? :)
https://jsfiddle.net/e3ec86rg/
<div id="blogtitle">
<center>
<div id="arrow">⬇</div>
<div style="font-size:18px">Now go <span style="color:{color:permalink border}">that way</span></div>
</center>
edit: This is what bothers me the arrow is a little bit lower than the text.
It's due to float property. Add a negative margin to offset it...
#arrow {
font-size: 18px;
-webkit-animation: bounce 2s infinite ease-in-out;
margin-top: -2px; /* edit as you need */
float: left;
}
jsfiddle
#arrow {
font-size: 18px;
-webkit-animation: bounce 2s infinite ease-in-out;
margin-top: -2px;
float: left;
}
#-webkit-keyframes bounce {
0%,
20%,
60%,
100% {
-webkit-transform: translateY(0);
}
40% {
-webkit-transform: translateY(-20px);
}
80% {
-webkit-transform: translateY(-10px);
}
}
#blogtitle {
position: relative;
height: auto;
z-index: 5;
text-transform: uppercase;
color: {
color: blog title
}
;
font-size:150px;
letter-spacing:2px;
font-weight:bold;
text-align:left;
width:250px;
padding-top: 10px;
padding-left: 10px;
}
<div id="blogtitle">
<center>
<div id="arrow">⬇</div>
<div style="font-size:18px">Now go <span style="color:{color:permalink border}">that way</span></div>
</center>
</div>
Check this
Fiddle
<div id="arrow" style=" margin-top: -3px;">⬇</div>
You can change your transform values:
#-webkit-keyframes bounce {
0%, 20%, 60%, 100% { -webkit-transform: translateY(-5px); }
40% { -webkit-transform: translateY(-25px); }
80% { -webkit-transform: translateY(-15px); }
}
#arrow {
color:{color:permalink border};
font-size:18px;
float:left;
-webkit-animation: bounce 2s infinite ease-in-out;
}
#-webkit-keyframes bounce {
0%, 20%, 60%, 100% { -webkit-transform: translateY(-5px); }
40% { -webkit-transform: translateY(-25px); }
80% { -webkit-transform: translateY(-15px); }
}
#blogtitle{
position:relative;
height:auto;
z-index:5;
text-transform:uppercase;
color:{color:blog title};
font-size:150px;
letter-spacing:2px;
font-weight:bold;
text-align:left;
width:250px;
padding-top: 10px;
padding-left: 10px;
}
<div id="blogtitle">
<center>
<div id="arrow">⬇</div>
<div style="font-size:18px">Now go <span style="color:{color:permalink border}">that way</span></div>
</center>
</div>
I am relatively a newbie in the field of CSS. I have seen the #KEYFRAME element for displaying an animation that moves from one side to another. But I was just wondering how is it possible to move an image(in terms of an animation) that moves from one side to another as the page loads?
All answers are appreciated in advance
Thanks
div
{
width:100px;
height:100px;
background:red;
position:relative;
-webkit-animation:myfirst 5s; /* Chrome, Safari, Opera */
animation:myfirst 5s;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes myfirst
{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
/* Standard syntax */
#keyframes myfirst
{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
Please check the following fiddle for a back and forth image animation http://jsfiddle.net/jHHnN/ In the html apply the class "imganim" to the image tag and add the below CSS
.imganim
{
width:100px;
height:100px;
position:relative;
-webkit-animation:myfirst 5s infinite; /* Chrome, Safari, Opera */
animation:myfirst 5s;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes myfirst
{
0% { left:0px; top:0px;-webkit-transform:rotate(0deg)}
50% {left:100%; margin-left:-100px;-webkit-transform:rotate(360deg)}
100% {left:0px; top:0px;-webkit-transform:rotate(0deg)}
}
/* Standard syntax */
#keyframes myfirst
{
0% { left:0px; top:0px;transform:rotate(0deg)}
50% {left:100%; margin-left:-100px;transform:rotate(360deg)}
100% {left:0px; top:0px;transform:rotate(0deg)}
}
You can use transform css3 property
see this example : http://jsfiddle.net/R65pL/
<span>
<img src="https://pbs.twimg.com/profile_images/1134660580/Puerco_Potter.jpg" alt="">
</span>
span{
width: 100%;
padding: 30px;
display inline-block;
}
img{
-webkit-transition: all .4s;
-moz-transition: all .4s;
-ms-transition: all .4se;
-o-transition: all .4s;
transition: all .4s;
}
img:hover{
-webkit-transform: translateX(20px);
-moz-transform: translateX(20px);
-ms-transform: translateX(20px);
-o-transform: translateX(20px);
transform: translateX(20px);
}
see more in : http://www.w3schools.com/css/css3_transitions.asp
clock Here ho read a complete guide about css animations.
This is the fiddle.I have searched a solution for this but didn't find one. The correct one should be the one in Chrome/Opera/Safari. I want to show only the image from top to bottom.
The HTML:
<div class="container">
<img class="image" src="http://www.hotel-aramis.com/slider/home/notre-dame-de-paris.jpg" />
</div>
The CSS:
#-webkit-keyframes pan {
0% {
-webkit-transform: translate(0%, 0%);
}
100% {
top: 100%;
-webkit-transform: translate(0%, -100%);
}
}
#keyframes pan {
0% {
-webkit-transform: translate(0%, 0%);
}
100% {
top: 100%;
-webkit-transform: translate(0%, -100%);
}
}
.container {
position:relative;
width:1100px;
height:480px;
overflow:hidden;
background-color:#000;
}
.image {
position:absolute;
top: 0;
max-width:100%;
min-width:100%;
-webkit-animation: pan 5s alternate infinite linear;
animation: pan 5s alternate infinite linear;
}
Firefox doesn't use webkit why your -webkit-transform will do nothing. Change it to transform and it should most likely work.
I made a JSFiddle for you
#-webkit-keyframes pan {
0% {
-webkit-transform: translate(0%, 0%);
}
100% {
top: 100%;
-webkit-transform: translate(0%, -100%);
}
}
#keyframes pan {
0% {
transform: translate(0%, 0%);
}
100% {
top: 100%;
transform: translate(0%, -100%);
}
}