Text transition on hover image - css

I'am trying to set css transition on the text on hover image like this -> https://victorthemes.com/themes/glazov/portfolio-grid/
I tried to do this with cubic-bezier() function, but without result.
Here's my code.
* {
margin: 0;
padding: 0;
border: 0;
}
.img__wrap {
position: relative;
height: 200px;
width: 257px;
}
.img__description {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(29, 106, 154, 0.72);
color: #fff;
visibility: hidden;
opacity: 0;
transition: opacity .2s, visibility .2s;
}
.img__wrap:hover .img__description {
visibility: visible;
opacity: 1;
}
<div class="img__wrap">
<img class="img__img" src="http://placehold.it/257x200.jpg" />
<p class="img__description">Teext.</p>
</div>
Please give me some hints how to do this.

To darken the image, you need to change the opacity of it. To zoom the image, use a scale transform and to move the caption text, you need a translateX transform. Apply those css styles and their respective transitions (you need a transition in the image as well as in the text) and you're left with the following:
* {
margin: 0;
padding: 0;
border: 0;
}
.img__wrap {
position: relative;
background: black;
height: 200px;
width: 257px;
overflow: hidden;
}
.img__img {
opacity: 1;
transition: all 0.2s;
}
.img__description {
position: absolute;
color: #fff;
transition: all .2s;
left: 15px;
right: 0;
bottom: 15px;
transform: translateX(-100%);
}
.img__wrap:hover .img__img {
opacity: 0.5;
transform: scale(1.2);
}
.img__wrap:hover .img__description {
transform: translateX(0);
}
<div class="img__wrap">
<img class="img__img" src="http://placehold.it/257x200.jpg" />
<p class="img__description">Teext.</p>
</div>

I used transform: translate(); to move object. Play with cubic-bezier here to achieve perfect animation. But I used the same which was on the website you posted in example.
Also I removed opacity, visibility
* {
margin: 0;
padding: 0;
border: 0;
}
.img__wrap {
position: relative;
height: 200px;
width: 257px;
}
.img__description {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(29, 106, 154, 0.72);
color: #fff;
transform: translateX(-100%);
transition: all 600ms cubic-bezier(0.645, 0.045, 0.095, 1.08);
}
.img__wrap:hover .img__description {
transform: translate(0);
}
<div class="img__wrap">
<img class="img__img" src="http://placehold.it/257x200.jpg" />
<p class="img__description">Teext.</p>
</div>

Ok, first, I would suggest using "all" for the transition element instead of defining the same values for all of the proprieties you want to transition.
transition: all .2s;
Second, let's get the bezier right. I think this is close enough:
cubic-bezier(1.000, 0.215, 0.355, 0.990)
So the transition propriety should look like this:
transition: all .2s cubic-bezier(1.000, 0.215, 0.355, 0.990);
For the text animation I suggest using animate.css and use fadeInLeft.

Related

CSS, multiple animations on one element

I want to applay a flicker animation to one button when the page is loaded (after a small delay) AND the same animation when the button is hovered. However, only one of the animations works. When both animations are not commented out, the animation when the page is loaded works. When I comment out this animation, the hover animation works. I don't understand, why it's like that.
HTML Code:
<div class="container">
Hello
</div>
CSS Code:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
height: 100vh;
background-image: linear-gradient(
to right bottom,
rgba(72, 80, 92, 0.444),
rgba(43, 43, 46, 0.757)
);
}
.btn:link,
.btn:visited {
text-decoration: none;
background-color: #fff;
color: rgb(70, 70, 70);
padding: 15px 40px;
display: inline-block;
border-radius: 100px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.btn::after {
content: "";
display: inline-block;
height: 100%;
width: 100%;
border-radius: 100px;
position: absolute;
top: 0;
left: 0;
z-index: -1;
background-color: #fff;
animation: flickerButton 0.4s 1s;
}
.btn:hover::after {
animation: flickerButton 0.4s;
}
#keyframes flickerButton {
0% {
transform: scaleX(1) scaleY(1);
opacity: 1;
}
100% {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}
}
Thank you very much for your support.
The problem is that the same animation keyframes are set on the actual pseudo element and when the element is hovered.
CSS reckons that once it's run the animation it doesn't need to do it again.
Assuming a CSS-only solution is required, this snippet has two copies of the keyframes, one for the non hovered condition, which runs the once, and one for when it is hovered when it runs once but then when unhovered the pseudo element doesn't have the animation set any more etc.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
height: 100vh;
background-image: linear-gradient( to right bottom, rgba(72, 80, 92, 0.444), rgba(43, 43, 46, 0.757));
}
.btn:link,
.btn:visited {
text-decoration: none;
background-color: #fff;
color: rgb(70, 70, 70);
padding: 15px 40px;
display: inline-block;
border-radius: 100px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.btn::after {
content: "";
display: inline-block;
height: 100%;
width: 100%;
border-radius: 100px;
position: absolute;
top: 0;
left: 0;
z-index: -1;
background-color: #fff;
animation: flickerButton 0.4s 1s;
}
.btn:hover::after {
animation: flickerButton1 0.4s;
}
#keyframes flickerButton {
0% {
transform: scaleX(1) scaleY(1);
opacity: 1;
}
100% {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}
}
#keyframes flickerButton1 {
0% {
transform: scaleX(1) scaleY(1);
opacity: 1;
}
100% {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}
}
<div class="container">
Hello
</div>
You need to define the animation-iteration-count on the pseudo element. It's inheriting the default of running once (which happens on page load).
You can share the key-frames of flickerButton, but need to define infinite on the pseudo element so that it will loop forever on hover. You can do it shorthand on the single animation property, as follows:
.btn:hover::after {
animation: flickerButton 0.4s infinite;
}

how to create hover animation on a div

I wanted to create a div which has a background image and a transparent background color over it with some text. When hover, the transparent background color should slide out towards the bottom of the div as shown in the image:
https://i.ibb.co/pJFPvFB/Screenshot-2019-03-26-Zeplin-Project.png
Left block is default. Right block is hover state.
I modified this snippet: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_fade
I modified the provided style to:
<style>
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.container .overlay {
opacity: 0.75;
}
.container:hover .overlay {
opacity: 0;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
</style>
Edited:
My Problem
I tried to achieve a simple slideout animation on my as shown in the image I provided. See this: https://i.ibb.co/pJFPvFB/Screenshot-2019-03-26-Zeplin-Project.png
I have tried something like this - https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_fade
I edited the css they provided to the css I provided above.
Please see the image I provided. I wanted to achieve that.
Try this.
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
transition: .5s ease;
background-color: #008CBA;
}
.container:hover .overlay {
transition: .5s ease;
height: 0;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
<div class="container">
<img src="https://i.ibb.co/pJFPvFB/Screenshot-2019-03-26-Zeplin-Project.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
Hope this code may help you.
Hi hope this is what you are looking for
Try this fiddle
.container:hover .overlay {
animation-name: slideDown;
-webkit-animation-name: slideDown;
animation-duration: 1s;
-webkit-animation-duration: 1s;
animation-timing-function: ease;
-webkit-animation-timing-function: ease;
opacity: 1 !important;
}
hope this is what you are looking
.box {
width: 200px; height: 100px;
background-size: 100% 200%;
background-image: linear-gradient(to bottom, red 50%, black 50%);
-webkit-transition: background-position 1s;
-moz-transition: background-position 1s;
transition: background-position 1s;}
http://jsfiddle.net/jxgrtmvy

RadiateOut with css animation

I had a question to all the css wizards out there. I came across this CSS animation effect I have not seen before and wondered if anyone knew how it was done? https://www.landr.com/en
Just curious.
Best regards,
Philippe
Use a pseudo element to draw the circle that will radiate out, then use transform: scale() and opacity to cause it to grow and fade out.
using animation
div {
width: 100px;
height: 100px;
cursor: pointer;
position: relative;
}
div::after {
content: '';
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
}
div:hover::after {
animation: radiate .5s;
}
div, div::after {
background: #09c;
border-radius: 50%;
}
#keyframes radiate {
to {
transform: scale(1.5);
opacity: 0;
}
}
<div></div>
Or using transition
div {
width: 100px;
height: 100px;
cursor: pointer;
position: relative;
}
div::after {
content: '';
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
}
div:hover::after {
transform: scale(1.5);
opacity: 0;
transition: transform .5s, opacity .5s;
}
div, div::after {
background: #09c;
border-radius: 50%;
}
<div></div>

CSS hover transitions doesn't work

I'm having problems with getting any form of transition on this hover. I want it to appear a little slower than just abruptly when hovering over it. So maybe just a delay? Or an ease? Anyway I can't seem to get any of these things to work.
.forum-image {
float: left;
width: 75%;
overflow: auto;
position: relative;
opacity: 1;
transition: opacity 0.3 ease-in;
-webkit-transition: opacity 0.3 ease-in;
background-color: #dcdcdc;
}
.forum-image:hover .descriptionbox {
visibility: visible;
}
.descriptionbox {
opacity: 0.8;
background-color: #FFF;
width: 100%;
height: 100%;
visibility: hidden;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
box-sizing:border-box;
-moz-box-sizing:border-box; /* Firefox */
padding: 10px;
}
<div class="forum-image">
<img src="http://i.imgur.com/VwTgk9a.png">
<div class="descriptionbox">
Testtesttest
</div>
</div>
Instead of using "visibility:hidden" try changing just the opacity, like so:
.forum-image:hover .descriptionbox {
opacity: 0.8;
}
And then put the transition code on the description box:
.descriptionbox {
/* Other properties... */
padding: 10px;
opacity: 0; /* Start opacity at 0, changes when hovered... */
transition: opacity 0.3s ease-in;
}
Now the description box has the transition property, and when the image is hovered, the new opacity is applied (with the transition time set in the original class). Then that new opacity class is removed when the mouse exits the area.
Make sure you remove
visibility: hidden;
from the original code, or you'll never see anything! (This messed me up at first when i was trying to fix it)
Here is a JSfiddle for demonstration
.forum-image {
position: relative;
display: inline-block;
}
.descriptionbox {
position: absolute;
background: #ffffff;
left: 0;
top: 0;
right: 0;
bottom: 0;
opacity: 0;
-webkit-transition: opacity 1s; /* For Safari 3.1 to 6.0 */
transition: opacity 1s;
}
.descriptionbox:hover {
opacity: 1;
}
<div class="forum-image">
<img src="http://i.imgur.com/VwTgk9a.png" />
<div class="descriptionbox">
Testtesttest
</div>
</div>

CSS transition between left -> right and top -> bottom positions

Is it possible to use CSS transitions to animate something between a position set as left: 0px to right: 0px so it goes all the way across the screen? I need to accomplish the same thing with top to bottom. Am I stuck calculating the screen width / object-size?
#nav {
position: absolute;
top: 0px;
left: 0px;
width: 50px;
height: 50px;
-webkit-transition: all 0.5s ease-out;
}
.moveto {
top: 0px;
right: 0px;
}
and then I use jQuery's .addClass
You can animate the position (top, bottom, left, right) and then subtract the element's width or height through a CSS transformation.
Consider:
$('.animate').on('click', function(){
$(this).toggleClass("move");
})
.animate {
height: 100px;
width: 100px;
background-color: #c00;
transition: all 1s ease;
position: absolute;
cursor: pointer;
font: 13px/100px sans-serif;
color: white;
text-align: center;
}
/* ↓ just to position things */
.animate.left { left: 0; top: 50%; margin-top: -100px;}
.animate.right { right: 0; top: 50%; }
.animate.top { top: 0; left: 50%; }
.animate.bottom { bottom: 0; left: 50%; margin-left: -100px;}
.animate.left.move {
left: 100%;
transform: translate(-100%, 0);
}
.animate.right.move {
right: 100%;
transform: translate(100%, 0);
}
.animate.top.move {
top: 100%;
transform: translate(0, -100%);
}
.animate.bottom.move {
bottom: 100%;
transform: translate(0, 100%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Click to animate
<div class="animate left">left</div>
<div class="animate top">top</div>
<div class="animate bottom">bottom</div>
<div class="animate right">right</div>
And then animate depending on the position...
For elements with dynamic width it's possible to use transform: translateX(-100%); to counter the horizontal percentage value. This leads to two possible solutions:
1. Option: moving the element in the entire viewport:
Transition from:
transform: translateX(0);
to
transform: translateX(calc(100vw - 100%));
#viewportPendulum {
position: fixed;
left: 0;
top: 0;
animation: 2s ease-in-out infinite alternate swingViewport;
/* just for styling purposes */
background: #c70039;
padding: 1rem;
color: #fff;
font-family: sans-serif;
}
#keyframes swingViewport {
from {
transform: translateX(0);
}
to {
transform: translateX(calc(100vw - 100%));
}
}
<div id="viewportPendulum">Viewport</div>
2. Option: moving the element in the parent container:
Transition from:
transform: translateX(0);
left: 0;
to
left: 100%;
transform: translateX(-100%);
#parentPendulum {
position: relative;
display: inline-block;
animation: 2s ease-in-out infinite alternate swingParent;
/* just for styling purposes */
background: #c70039;
padding: 1rem;
color: #fff;
font-family: sans-serif;
}
#keyframes swingParent {
from {
transform: translateX(0);
left: 0;
}
to {
left: 100%;
transform: translateX(-100%);
}
}
.wrapper {
padding: 2rem 0;
margin: 2rem 15%;
background: #eee;
}
<div class="wrapper">
<div id="parentPendulum">Parent</div>
</div>
Demo on Codepen
Note: This approach can easily be extended to work for vertical positioning. Visit example here.
This worked for me on Chromium. The % for translate is in reference to the size of the bounding box of the element it is applied to so it perfectly gets the element to the lower right edge while not having to switch which property is used to specify it's location.
topleft {
top: 0%;
left: 0%;
}
bottomright {
top: 100%;
left: 100%;
-webkit-transform: translate(-100%,-100%);
}
In more modern browsers (including IE 10+) you can now use calc():
.moveto {
top: 0px;
left: calc(100% - 50px);
}

Resources