Hover animation backwards - css

Is there a way to animate the "hover out" in pure CCS? In the example below, all the action post hovering is doing exactly what is suppose to do, the problem comes when the animation / transition going backwards after hovering out. I need my div "tiny" animating back the way is animating in (right now the width is going back without transition) and my whatsapp icon is doing the other way around (I need to change the opacity without fading after hovering out).
In one of my approaches, I change the animation on my div with a transition: opacity (like the WA icon), BUT did not find a way to do the bouncy effect that is required. On the other hand the icon did not respond after insert a #keyframes inside the hover action (maybe out of scope?).
body {
background-color: blue;
}
.whatsapp-icon {
position: fixed;
left: 200px;
top: 30px;
opacity: 0;
transition: opacity 0.2s;
}
.tiny:hover+.whatsapp-icon {
opacity: 1;
}
.tiny:hover {
animation: animateDiv 0.4s;
animation-fill-mode: forwards;
}
.tiny {
position: fixed;
opacity: 1;
background-color: rgb(255, 255, 255);
border: 1px solid rgb(228, 231, 235);
border-radius: 15px;
width: 200px;
height: 100px;
box-shadow: 3px 3px 10px black;
}
.box {
position: fixed;
width: 200px;
height: 100px;
cursor: default;
}
#keyframes animateDiv {
70% {
width: 255px;
}
85% {
width: 248px;
}
100% {
width: 250px;
}
}
<script type="module" src="index.js"></script>
<div class="container">
<div class="tiny">
<a class="box" href="https://api.whatsapp.com/send?phone=+XXXXXXXX" target="_blank">
</a>
</div>
<div class="whatsapp-icon">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/WhatsApp.svg/240px-WhatsApp.svg.png" width="50" height="50">
</div>
</div>
Hopefully someone can give me a hint. Thx in advance.

Use a transition instead:
body {
background-color: blue;
}
.whatsapp-icon {
position: fixed;
left: 200px;
top: 30px;
opacity: 0;
transition: opacity 0.2s;
}
.tiny:hover+.whatsapp-icon {
opacity: 1;
}
.tiny:hover {
width: 250px;
}
.tiny {
position: fixed;
opacity: 1;
background-color: rgb(255, 255, 255);
border: 1px solid rgb(228, 231, 235);
border-radius: 15px;
width: 200px;
height: 100px;
box-shadow: 3px 3px 10px black;
transition: width 0.4s;
}
.box {
position: fixed;
width: 200px;
height: 100px;
cursor: default;
}
<script type="module" src="index.js"></script>
<div class="container">
<div class="tiny">
<a class="box" href="https://api.whatsapp.com/send?phone=+XXXXXXXX" target="_blank">
</a>
</div>
<div class="whatsapp-icon">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/WhatsApp.svg/240px-WhatsApp.svg.png" width="50" height="50">
</div>
</div>
Transitions can do/undo without the user having to show the points of change.

Related

Adding Blur Effect On Image

For adding blur effect on image, I create another element from the same image with absolute position, low opacity and blur effect. I don't think this is efficient. What's the best approach for this situation?
<img src="./images/shopping.svg" />
<img style="position: absolute;opacity: 0.5;filter: blur(10px);" src="./images/shopping.svg" />
Preview
You can use drop-shadow filter, to achieve the desired effect. This also kills the need of using second img tag.
body{
background: #222;
}
img{
filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.5)) invert(100%);
/* Note - I used invert(100%) to invert the colors since the original svg was black.
If you want to remove it, you need to use rgba(255, 255, 255, 0.5) for white
shadow.
*/
}
<img src="https://www.svgrepo.com/show/80543/shopping-cart-outline.svg" width="300" />
blur hover effect using like this may be it's helping us:
.column {
margin: 15px 15px 0;
padding: 0;
}
.column:last-child {
padding-bottom: 60px;
}
.column::after {
content: '';
clear: both;
display: block;
}
.column div {
position: relative;
float: left;
width: 300px;
height: 200px;
margin: 0 0 0 25px;
padding: 0;
}
.column div:first-child {
margin-left: 0;
}
.column div span {
position: absolute;
bottom: -20px;
left: 0;
z-index: -1;
display: block;
width: 300px;
margin: 0;
padding: 0;
color: #444;
font-size: 18px;
text-decoration: none;
text-align: center;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
opacity: 0;
}
figure {
width: 300px;
height: 200px;
margin: 0;
padding: 0;
background: #fff;
overflow: hidden;
}
figure:hover+span {
bottom: -36px;
opacity: 1;
}
/* Blur */
.hover07 figure img {
-webkit-filter: blur(3px);
filter: blur(3px);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.hover07 figure:hover img {
-webkit-filter: blur(0);
filter: blur(0);
}
<div class="hover07 column">
<div>
<figure><img src="https://picsum.photos/300/200?image=244" /></figure>
<span>Hover</span>
</div>
<div>
<figure><img src="https://picsum.photos/300/200?image=1024" /></figure>
<span>Hover</span>
</div>
</div>

Transition on page re-visit

I have a simple transform & transition on a div element. However, it doesn't appear to be working on page loads/re-visits.
Really appreciate if I could be directed to a possible solution.
.container {
width: 50%;
text-align: center;
background: #ccff44;
padding: 50px 5px;
border: #000 2px solid;
margin: auto;
transform: translate3D(-50px, 0, 0);
transition: all 2s ease-in;
}
<div class="container">
<p>Main paragraph</p>
</div>
Hello I think what you are looking for is an animation
the transition will not trigger any movement on its own
#keyframes enter {
from {
transform: translateX(-50px);
}
to {
transform: translateX(0px);
}
}
.container {
width: 50%;
text-align: center;
background: #ccff44;
padding: 50px 5px;
border: #000 2px solid;
margin: auto;
animation: enter 2s linear;
}
<div class="container">
<p>Main paragraph</p>
</div>

Getting rid of funny hover behaviour when changing div width

I have some videos with a background overlay and text over them and my goal is having this overlay and the text disappearing on hover. I've managed to achieve this but if I change the width of the div containing the text (class .project-content on code below), I get a funny transparency behaviour on hover.
Would anyone be able to help by letting me know how I can modify the width of said div while keeping the intended behavior on hover? Thank you very much!
Here's my code:
HTML
<div class="works-content">
<div class="video-background">
<a href="#" target="_bank">
<div class="video">
<video loop="" muted="muted" poster="" playsinline=""><source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4"></video>
</div>
</a>
<div class="project-content">
<p class="project-title">TITLE</p>
<p class="project-description">PROJECT DESCRIPTION</p>
</div>
</div>
</div>
CSS
.works-content {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 60px 30px;
padding: 0px 30px 100px 30px;
}
.video-background {
background: $black;
position:relative;
transition: 0.5s ease;
width: 100%;
}
.video-background:hover {
transform: scale(1.04);
transition: 0.5s ease;
background: white;
}
.video-background:hover .project-title a, .project-description a {
display: none;
}
.video {
transition: 0.5s ease;
opacity: 0.2;
}
.video:hover {
transition: 0.5s ease;
opacity: 1;
}
video {
width: 100%;
}
.project-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.project-content a {
color: white;
}
.project-title a {
font-size: 36px;
letter-spacing: 2px;
font-weight: bold;
border-bottom: 10px solid $yellow;
}
.project-title a:hover {
text-decoration: none;
}
.project-description {
font-size: 36px;
padding-top: 8px;
letter-spacing: 1px;
}
JS
jQuery('.video-background').mouseover(function(){
$('video', this).get(0).play();
}).mouseout(function(){
$('video', this).get(0).pause();
});

CSS - Element visible on backface after flip

I'm working on a CSS flip card and ran into this issue, when despite backface-visibility: hidden; an element still visible from the other side.
If you run the (simplified here) snippet and click more in the bottom right corner - the card flips, but the more stays visible. It's probably because of the position: absolute, because the other element behaves as expected.
So my question - is it possible to fix that (preferably with CSS only) and still have the background semi-transparent?
document.querySelector('.card').addEventListener('click', function(e) {
if (e.target.nodeName !== 'I') return;
e.target.parentNode.parentNode.classList.toggle('flip');
});
html, body {
height: 100%;
background: linear-gradient(90deg, #9EFFBE 0, #F4FFC7 45%, #F4FFC7 55%, #ADFCFF 100%);
}
.logo {
background: yellow;
border: 8px solid #fff;
border-radius: 50%;
display: block;
height: 120px;
margin: 1em auto;
width: 120px;
}
.item {
border: 1px solid transparent;
display: flex;
height: 170px;
margin: 0 auto .75em;
perspective: 800px;
position: relative;
width: 40%;
}
.card {
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: transform 1s;
}
.card figure {
margin: 0;
display: block;
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.card i {
cursor: pointer;
display: inline-block;
position: absolute;
right: .5em;
bottom: .5em;
}
.card.flip {
transform: rotateY(180deg);
}
.card--front {
background: rgba(255, 255, 255, 0.33);
border: 1px solid #fff;
position: relative;
}
.card--back {
background: #D9FAEF;
background: rgba(255, 255, 255, 0.33);
text-align: center;
position: relative;
transform: rotateY(180deg);
}
<article class="item">
<div class="card">
<figure class="card--front">
<div class="logo"></div>
<i class="icon icon--info-circled">more</i>
</figure>
<figure class="card--back">
<i class="icon icon--cancel-circled">close</i>
</figure>
</div>
</article>
EDIT
.card.flip .card--front {
transition-delay: 0.3s;
visibility: hidden;
}

Newbie in Css. Can't get to duplicate a tutorial about CSS animation of a frog

This is kind of embarassing for me, but I have a final project for my Software engineering class, and I'd been searching for tutorials so I can see and learn about html css and javascript to implement it in my project. I never worked on those, so I found a cool tutorial about some animation that I wanted to implement in my project so I decided to give it a try, and I cant get the code to work.
Here's the tutorial link.
http://davidwalsh.name/logo-animation
Here's my code (http://jsfiddle.net/5x4wv/):
<!DOCTYPE html>
<html>
<head>
<body>
<div class="mike">
<div class="head">
<div class="eyes">
<div class="eye">
<div class="pupil"></div>
</div>
<div class="eye">
<div class="pupil"></div>
</div>
</div>
<div class="nose">
<div class="ball"></div>
<div class="ball"></div>
</div>
<div class="mouth"></div>
</div>
</div>
<style>
div {
border-radius: 50%;
box-sizing: border-box;
}
.mike {
width: 400px;
margin: 0 auto;
padding-top: 2%;
transition: all 1s;
}
.mike:hover {
transform: scale(1.5) rotate(360deg);
}
.head {
width: 195px;
height: 120px;
background: #92ae57;
position: relative;
z-index: 1;
margin-left: 103px;
}
.eyes {
width:200px;
position: absolute;
bottom: 45px;
}
.eye {
width: 95px;
height: 93px;
background-color: #ffe13b;
border: 10px solid #92ae57;
display: inline-block;
z-index: 2;
animation: eyes 5s infinite step-start 0s;
}
.eye:last-child {
float:right;
}
.pupil {
width: 1px;
height: 1px;
border: 10px solid #353535;
display: inline-block;
position: absolute;
top: 38px;
margin-left:27px;
z-index: 3;
animation: pupil 5s infinite step-start 0s;
}
.pupil:last-child{
float:right;
}
.ball {
width: 1px;
height: 1px;
border: 5px solid #6f8346;
position: absolute;
top: 70px;
left: 88px;
}
.ball:last-child {
float:left;
margin-left: 14px;
}
.mouth {
height: 100px;
width: 180px;
border-bottom: 4px solid #6f8346;
position: relative;
top: 8px;
left: 7px;
}
/* Animations */
#keyframes eyes {
0%, 100% {
background: #92ae57;
border-radius: 50%;
border: 10px solid #92ae57;
}
5%, 95% {
background:#ffe13b;
border-radius: 50%;
border: 10px solid #92ae57;
}
}
#keyframes pupil {
0%, 100% {
opacity: 0;
}
5%, 95% {
opacity: 1;
}
}
</style>
</body>
</html>
I'm using Sublimetext 2 and running in Chrome.
Prefix stuff...
Delay duration only delays animation at first start not at every iteration.
USE FLOATS BARELY...use relative position especially for this..
http://jsfiddle.net/T862G/ take a look it works
#-webkit-keyframes eyes {
10% {background-color:#92ae57;}
25% {background-color:#ffe13b;}
}
#-webkit-keyframes pupil {
10% {opacity: 0;}
25% {opacity: 1;}
}
.mike:hover {
-webkit-transform: rotate(360deg) scale(1.5);
}

Resources