Apply hover out ease effect using css animation - html

On this LIVE DEMO you can see how animation works in each div moves its image and gives opacity:1 to text.
When hover-off, naturally all styles get back to their initial state directly, but I want them to do it smoothly(ease), instead of setting all initial styles at the same time with no progress.
Here it is related animation code:
#highlights div[class*="high-"]:hover > p {
-webkit-animation:downOp 0.3s ease-in 0s forwards;
-ms-animation:downOp 0.3s ease-in 0s forwards;
animation:downOp 0.3s ease-in 0s forwards;
}
#highlights div[class*="high-"]:hover > .image {
-webkit-animation:imgTrans 5s ease-out 0s forwards;
-ms-animation:imgTrans 5s ease-out 0s forwards;
animation:imgTrans 5s ease-out 0s forwards;
}
#-webkit-keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
#-ms-keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
#keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
#-webkit-keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;
}
}
#-ms-keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;
}
}
#keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;
}
}

Use css transform instead of css animation! It will automatically handle hover-out effect!
See your fiddle here
See my modified effect jsfiddle
html
<article id="highlights">
<div class="high-rinoplastia">
<div class="image"></div>
<p><strong>Rinoplastia</strong>
<br> <span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod</span>
</p>
</div>
</article>
css
#highlights {
min-height: 525px;
width: 1170px;
margin:0 auto;
}
#highlights div[class*="high-"] {
border: 1px solid rgba(0, 0, 0, 0.28);
display: inline-block;
float: left;
height: 150px;
margin: 10px;
position: relative;
width: calc(33% - 20px);
overflow: hidden;
}
#highlights .image {
height:100%;
transition:all 4s ease;
}
#highlights p {
background-color: white;
bottom: 0;
height: 60px;
margin-bottom: 0px;
position: absolute;
opacity:0.7;
transition:all 0.6s ease;
}
#highlights span {
display: block;
font-size: 12px;
margin: 2px;
}
#highlights:hover p {
opacity:1;
}
#highlights:hover .image {
transform:all 5s ease;
margin-right: -50px;
}
#highlights .high-rinoplastia .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-venas .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-cirugiaCalvicie .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-tratamientoCalvicie .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}

Everything remains same just add transition to p and image element.
#highlights .image {
height:100%;
-webkit-transition: all 0.5s ease; // increase 0.5s to whatever you wish in order to add more smoothness
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#highlights p {
background-color: white;
bottom: 0;
height: 60px;
margin-bottom: 0px;
position: absolute;
opacity:0.7;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}

Related

Crossfading image hides other elements

I'm trying to make two images crossfade when you hover over them, and it works besides the fact that it hides the text I need. The text should be under the image instead of behind it. How can I fix this?
#center {
text-align: center;
}
#under {
text-align: center;
margin: 0;
max-width: 50%;
margin-left: auto;
margin-right: auto;
}
#crossfade {
position: relative;
}
#crossfade img {
position: absolute;
left: 0;
opacity: 1;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
#crossfade img.top:hover {
opacity: 0;
}
img {
margin-right: 3%;
max-width: 65%
}
#goofy {
margin: 0;
margin-bottom: 40px;
}
<div id="center">
<div id="crossfade">
<img id="goofy" src="https://inpulse.eli328.repl.co/half.png" alt="half" class="bottom">
<img id="goofy" src="https://inpulse.eli328.repl.co/active.png" alt="active" class="top">
</div>
<p id="under">
The Inpulse creates a powerful electric charge that when reaching sufficient levels, creates a bright arc of lightining between the two prongs. The handheld device will definitely satisfy its user.
</p>
</div>
Give #crossfade width & height.
#center {
text-align: center;
}
#under {
text-align: center;
margin: 0;
max-width: 50%;
margin-left: auto;
margin-right: auto;
}
#crossfade {
position: relative;
width: 500px;
height: 330px;
}
#crossfade img {
position: absolute;
left: 0;
opacity: 1;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
#crossfade img.top:hover {
opacity: 0;
}
img {
margin-right: 3%;
max-width: 65%
}
#goofy {
margin: 0;
margin-bottom: 40px;
}
<div id="center">
<div id="crossfade">
<img id="goofy" src="https://inpulse.eli328.repl.co/half.png" alt="half" class="bottom">
<img id="goofy" src="https://inpulse.eli328.repl.co/active.png" alt="active" class="top">
</div>
<p id="under">
The Inpulse creates a powerful electric charge that when reaching sufficient levels, creates a bright arc of lightining between the two prongs. The handheld device will definitely satisfy its user.
</p>
</div>

How to move the block along its width (only css)

I want to move the block to the left along its length.
How I can do this?
simple example, pure css :
.mytext {
border: 8px black solid;
text-align: center;
font-size: 45px;
left: 300px;
width: inherit;
height: 60px;
transition: 2s;
-webkit-transition: 2s;
-moz-transition: 2s;
position: absolute;
}
.mytext:hover {
left: 0;
}
.mytext2 {
margin-top: 100px;
border: 8px black solid;
text-align: center;
font-size: 45px;
width: 300px;
height: 60px;
transition: 2s;
-webkit-transition: 2s;
-moz-transition: 2s;
position: absolute;
}
#keyframes slideToLeft {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(0);
}
}
.mytext2 {
/* This section calls the slideInFromLeft animation we defined above */
animation: 2s ease-out 0s 1 slideToLeft;
}
<div class="mytext">text</div>
<div class="mytext2">text2</div>

CSS Transition on hover: animate mouse-out as well

I want to animate a css-arrow (pointing to the left) on hover to move slightly right on hover and stay there. Once the mouse hovers out the arrow it should move backwards with the animation as well.
#-webkit-keyframes arrow-left {
0% {
-webkit-transform: translateX(0);
transform:translateX(0);
}
20% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
100% {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
}
}
#keyframes arrow-left {
0% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
20% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
100% {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
}
}
.arrow-icon.left:hover {
-webkit-animation:arrow-left 0.35s ease-in;
animation:arrow-left 0.35s ease-in;
-webkit-transform-origin:50% 0%;
-ms-transform-origin:50% 0%;
transform-origin:50% 0%
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
Any idea on how to make the animation out work as well, so it animates back and doesn't jump back?
https://jsfiddle.net/gsvjwxxj/
Instead of using keyframes to perform the translate, use transition plus cubic-bezier.
$(document).ready(function(){
$('.menu-icon').click(function(){
$(this).toggleClass('open');
});
/*setTimeout(function () {
$('.mouse-icon').fadeOut(250, function() { $(this).remove(); });
}, 5000);*/
});
* {
margin: 0;
padding: 0;
}
body {
margin: 100px;
}
/* ---------------------------------------------- /*
* Animated arrow icon
/* ---------------------------------------------- */
.arrow-icon {
position: relative;
width:26px;
height:4px;
background:#000;
cursor: pointer;
-webkit-transition: width .15s ease-in-out, -webkit-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
-moz-transition: width .15s ease-in-out, -moz-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
-o-transition: width .15s ease-in-out, -o-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
transition: width .15s ease-in-out, transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
}
.arrow-icon.left:hover, .arrow-icon.right:hover {
width:36px;
}
.arrow-icon.down:hover, .arrow-icon.up:hover {
height:36px;
}
.arrow-icon.down:hover:after{
top: 15px;
}
.arrow-icon:before {
position:absolute;
content:"";
}
.arrow-icon.left:before, .arrow-icon.right:before {
width: 52px;
height: 26px;
}
.arrow-icon.down:before, .arrow-icon.up:before {
width: 26px;
height: 52px;
}
.arrow-icon:before {
position:absolute;
content:"";
width: 52px;
height: 26px;
}
.arrow-icon.left:before {
top: -12px;
left: -12px;
}
.arrow-icon.right:before {
top: -12px;
left: -12px;
}
.arrow-icon.down:before {
top: -12px;
left: -12px;
}
.arrow-icon.up:before {
top: -12px;
left: -12px;
}
.arrow-icon:after {
position:absolute;
content:"";
transform:rotate(45deg);
top:-8px;
width:16px;
height:16px;
background:transparent;
border-color: #000;
}
.arrow-icon.left:after{
border-left:4px solid;
border-bottom:4px solid;
}
.arrow-icon.right:after{
right:0;
border-right:4px solid;
border-top:4px solid;
}
.arrow-icon.down, .arrow-icon.up {
width: 4px;
height: 26px;
left: 10px;
}
.arrow-icon.down:after{
top: 6px;
left:-8px;
border-right:4px solid;
border-bottom:4px solid;
}
.arrow-icon.up:after {
top:0px;
left:-8px;
border-right:4px solid;
border-top:4px solid;
transform:rotate(-45deg);
}
.arrow-icon.left{
-webkit-transform-origin:50% 0%;
-ms-transform-origin:50% 0%;
transform-origin:50% 0%;
}
.arrow-icon.left:hover {
transform:translateX(-12px);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="arrow-icon left"></div>
you don't have to use animation for this. you can just use transform:translateX(-12px)
see here > fiddle
or snippet below :
let me know if it helps
* {
margin: 0;
padding: 0;
}
body {
margin: 100px;
}
/* ---------------------------------------------- /*
* Animated arrow icon
/* ---------------------------------------------- */
.arrow-icon {
position: relative;
width:26px;
height:4px;
background:#000;
cursor: pointer;
-webkit-transition: .15s ease-in-out;
-moz-transition: .15s ease-in-out;
-o-transition: .15s ease-in-out;
transition: .15s ease-in-out;
}
.arrow-icon.left:hover, .arrow-icon.right:hover {
width:36px;
}
.arrow-icon:before {
position:absolute;
content:"";
}
.arrow-icon.left:before, .arrow-icon.right:before {
width: 52px;
height: 26px;
}
.arrow-icon:before {
position:absolute;
content:"";
width: 52px;
height: 26px;
}
.arrow-icon.left:before {
top: -12px;
left: -12px;
}
.arrow-icon:after {
position:absolute;
content:"";
transform:rotate(45deg);
top:-8px;
width:16px;
height:16px;
background:transparent;
border-color: #000;
-webkit-transition: .1s ease-in-out;
-moz-transition: .1s ease-in-out;
-o-transition: .1s ease-in-out;
transition: .1s ease-in-out;
}
.arrow-icon.left:after{
border-left:4px solid;
border-bottom:4px solid;
}
.arrow-icon.left:hover {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
-ms-transform-origin:50% 0%;
transform-origin:50% 0%;
}
<div class="arrow-icon left"></div>

Ease-in works for both text and background but ease-out only works for text. Why?

Ease-in only works for text and background but ease-out only works for text but not background.
article {
width: 100%;
height: 1000px;
background-color: #fffff;
color: #00000;
}
article .topnav {
opacity: 0;
transition: background-color .9s ease-out;
transition: background-color .9s ease-in;
-moz-transition: background-color .9s ease-in;
-webkit-transition: background-color .9s ease-in;
}
article .topnav {
background: rgba(0,0,0,0);
transition: opacity .9s ease-out;
transition: opacity .9s ease-in;
-moz-transition: opacity .9s ease-in;
-webkit-transition: opacity .9s ease-in;
}
article:hover p.topnav {
opacity: 0.7;
background-color: #808080;
}
.topnav {
visibility: invisible;
text-align: center;
margin: auto;
width: 50%;
}
<article>
<p class="topnav">I am topnav</p>
</article>
Please see fiddle.
The idea is so that when I hover in and out of , both the text and the background eases in and out together.
Please help.
You are setting both transitions on the unhovered state, thus the second one is overwriting the first rule. You need to apply transition rules to both unhovered and hovered state.
article {
width: 100%;
height: 1000px;
background-color: #fffff;
color: #00000;
}
article p.topnav {
opacity: 0;
background-color: #000;
transition: all .9s ease-out;
}
article:hover p.topnav {
opacity: 0.7;
background-color: #808080;
transition: all .9s ease-in;
}
.topnav {
text-align: center;
margin: auto;
width: 50%;
}
<article>
<p class="topnav">I am topnav</p>
</article>

Figuring out transistions

i'm trying to figure out how to work some transitions? i've got an overlay div that pops up when a link is clicked but i'm trying to make it so it either fades into the div ontop or it just melts into it?
<html>
<head>
<style type="text/css">
a:link, a:visited, a:active {
text-decoration: none;
}
html, body {
max-width: 100%;
max-height: 100%;
margin-right: auto;
margin-left: auto;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
}
.button {
margin-right: auto;
margin-left: auto;
width: 100%;
height: 100%;
float: left;
padding: 10px;
background-color: transparent;
font-weight:bold;
text-decoration:none;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
}
.blockpurp {
background: purple;
}
.blockyell {
background: yellow;
}
#cover {
position:fixed;
top:0;
left:0;
background:rgba(0,0,0,0.6);
z-index:5;
width:100%;
height:100%;
display:none;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease; }
#loginScreen, #loginScreen2 {
padding: 20px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
overflow: scroll;
height:100%;
width:100%;
margin:0 auto;
position:fixed;
top: 0px;
left: 0px;
z-index:10;
display:none;
background: rgba(0,0,0,1);
border:0;
color: #fff;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
}
#loginscreen2 {
background: rgba(23,44,1,0.9);
}
#loginScreen:target, #loginScreen:target + #cover, #loginScreen2:target, #loginScreen2:target + #cover{
display:block;
opacity:9;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease; }
.cancel {
display:block;
position:fixed;
top:0px;
right:0px;
background: transparent;
color:black;
text-shadow: 0px 0px 1px rgba(255,255,255,0.9);
height:30px;
width:35px;
font-size:30px;
text-decoration:none;
text-align:center;
font-weight:bold;
}
</style>
</head>
<body>
<div align="center">
<table align="center" width="900px" height="300px">
<td width="60%" class="blockpurp">click</td>
<td width="40%" class="blockyell">click</td>
</table>
</div>
<div id="loginScreen">
LOL LOL LOL
×
</div>
<div id="cover" >
</div>
<div id="loginScreen2">
stuff stuff
×
</div>
<div id="cover" >
</div>
</body>
</html>
i tried using this code string:
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
but that doesn't seem to work? any ideas?
The biggest problem is that you are going from display:none to display:block. There is no real way to transition between the two using css.
Instead, you could keep them all displayed and in a fixed position, but change the appearance using z-index.
Below is an example of how you could do this.
HTML:
<div id="center">
<table>
<td class="blockpurp">click</td>
<td class="blockyell">click</td>
</table>
</div>
<div id="loginScreen">
<div>
LOL LOL LOL
×
</div>
</div>
<div id="loginScreen2">
<div>
stuff stuff
×
</div>
</div>
CSS (in need of some serious organization!):
body {
position: relative;
}
#center {
position: fixed;
background: white;
width: 100%;
height: 100%;
z-index: 5;
}
table {
width: 100%;
height: 100%;
}
td {
position: relative;
min-height: 100%;
}
td a {
position: absolute;
width: 100%;
height: 100%;
top:0;
}
.blockpurp {
background: purple;
width: 60%;
}
.blockyell {
background: yellow;
width: 40%;
}
#loginScreen, #loginScreen2 {
opacity: 0;
position: fixed;
width: 100%;
height: 100%;
background:rgba(0,0,0,0.6);
top: 0;
z-index:1;
color: white;
}
#loginScreen div, #loginScreen2 div {
padding: 20px;
background: rgba(0,0,0,1);
}
.cancel {
position:fixed;
top:0px;
right:0px;
background: transparent;
color:black;
text-shadow: 0px 0px 1px rgba(255,255,255,0.9);
height:30px;
width:35px;
font-size:30px;
text-decoration:none;
text-align:center;
font-weight:bold;
}
#loginScreen:target, #loginScreen2:target {
opacity: 1;
-webkit-transition: opacity 3s;
-moz-transition: opacity 3s;
-ms-transition: opacity 3s;
-o-transition: opacity 3s;
transition: opacity 3s;
z-index:10;
}
I made the following changes in your html as well:
I took out the divs with the id 'cover'. Unlike classes, you should never have more than one element with a particular id per page. Id's should be completely unique.
I removed the inline styling. Style everything within your stylesheet!
Fiddle for reference
You need to use jquery in order to control mouse click event.
Here is a sample
$(".sample").click(function(){
$(".popup").css({
'visibility': 'visible',
'opacity': 1
});
});
As of yet, there is no way to do an HTML5 transition based on a link click. For now, you can toggle a class and attach the CSS transitions to the element being affected (which is faster + more lightweight anyway). If you attach the transition to the toggled class, then it will only do the transition when the toggled class is removed, not when it's added.
Here's an example that doesn't use jQuery—no reason to include an entire library, if you're not using it elsewhere.
HTML
<a id="clickme" href="#">click me</a>
<div id="test" class="clicked fun here">testing</div>
JavaScript
document.getElementById("clickme").onclick = function (event) {
var target = document.getElementById("test"),
classes = test.className.split(" "),
toggledClass = "clicked";
if (!!~classes.indexOf(toggledClass)) {
// same as if (classes.indexOf(toggledClass) > -1)
test.className = classes.join(" ").replace(toggledClass, "");
} else {
test.className = classes.join(" ") + " " + toggledClass;
}
}
CSS
div {
width: 100px;
height: 3em;
background-color: black;
color: white;
text-align: center;
-webkit-transition: all 250ms ease-in-out;
-moz-transition: all 250ms ease-in-out;
-ms-transition: all 250ms ease-in-out;
-o-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
}
.clicked {
color: red;
background-color: cyan;
}
fiddle