Hi what I am trying to do is have a with background color and on hover it will transition to a image. I found very good example but other way around here is a link.
http://jsfiddle.net/davidThomas/PbvFr/1/ so I need bg black and on :hover image will appear over time. I tried to do this but unfortunately the transition is not smooth. thank you for your time!!!!!!!!
.imageWrap {
background-color: #333;
border: 1px solid #000;
height: 300px;
moz-transition: all 1s linear;
ms-transition: all 1s linear;
o-transition: all 1s linear;
transition: all 1s linear;
webkit-transition: all 1s linear;
width: 300px;
}
.imageWrap .img {
moz-transition: all 1s linear;
ms-transition: all 1s linear;
opacity: 1;
o-transition: all 1s linear;
transition: all 1s linear;
webkit-transition: all 1s linear;
}
.imageWrap:hover {
background-image: url(5.jpg);
moz-transition: all 1s linear;
ms-transition: all 1s linear;
o-transition: all 1s linear;
transition: all 1s linear;
webkit-transition: all 1s linear;
}
.img:hover, .imageWrap:hover .img {
moz-transition: all 1s linear;
ms-transition: all 1s linear;
opacity: 0;
o-transition: all 1s linear;
transition: all 1s linear;
webkit-transition: all 1s linear;
}
Just reverse what he did: http://jsfiddle.net/PbvFr/102/
Change opacity from 0 to 1 rather than 1 to 0.
Look the CSS
Here you go: FIDDLE
CSS
.imgWrap {
display: inline-block;
position:relative;
border: 1px solid #000;
background-color: #000;
-moz-transition: all 1s linear;
-ms-transition: all 1s linear;
-o-transition: all 1s linear;
-webkit-transition: all 1s linear;
transition: all 1s linear;
height: 500px;
width:364px;
}
.imgWrap img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
background: #fff;
color: #fff;
opacity:0;
transition:1s;
}
.imgWrap:hover img {
opacity: 1;
-moz-transition: all 1s linear;
-ms-transition: all 1s linear;
-o-transition: all 1s linear;
-webkit-transition: all 1s linear;
transition: all 1s linear;
}
Related
I have a two-step CSS animation that I want to run forward once when "activated", and then run backward when "deactivated". I know it's possible to achieve by defining separate forward and backward animations, like so, but I was wondering if this was achievable with a single animation and the animation-direction: reverse property.
Something like this? If so what you're looking for is
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
If you need to attach it to a click you can add script to it in order to toggleClass with onClick
#test{
position:absolute;
height: 100px;
width: 100px;
background-color: #A8A8A8;
border-bottom: 0px solid black;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#test:hover{
border-bottom: 10px solid black;
}
<div id="test">
</div>
div {
background: aqua;
color: #fff;
margin: 0 auto;
padding: 100px 0;
-webkit-transition: -webkit-border-radius 1.5s ease-in;
-moz-transition: -moz-border-radius 1.5s ease-in;
-o-transition: border-radius 1.5s ease-in;
-ms-transition: border-radius 1.5s ease-in;
transition: border-radius 1.5s ease-in;
text-align: center;
width: 200px;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-o-transition: all 3s ease;
-ms-transition: all 3s ease;
transition: all 3s ease;
-webkit-transform: rotate(-360deg);
-moz-transform: rotate(-360deg);
-o-transform: rotate(-360deg);
-ms-transform: rotate(-360deg);
transform: rotate(-360deg);
}
div:hover {
background: red;
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
-webkit-transition: -webkit-border-radius 1.5s ease-in;
-moz-transition: -moz-border-radius 1.5s ease-in;
-o-transition: border-radius 1.5s ease-in;
-ms-transition: border-radius 1.5s ease-in;
transition: border-radius 1.5s ease-in;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-o-transition: all 3s ease;
-ms-transition: all 3s ease;
transition: all 3s ease;
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
<div></div>
I created a simple effect that causes an image to change color on hover. Now I want to add transition-timing-function properties so the color transition fades in and out rather than an instant change, but I can't seem to get it to work. Any ideas?
Here's the code:
div {
position: relative;
display: inline-block;
-webkit-transition: all 500ms ease-out 1s;
-moz-transition: all 500ms ease-out 1s;
-o-transition: all 500ms ease-out 1s;
transition: all 500ms ease-out 1s;
}
img {
width: 100%;
height: 100%;
}
div:hover::after {
position: absolute;
z-index: 1;
background-color: Indigo;
opacity: 0.4;
left: 0;
top: 0;
height: 100%;
width: 100%;
content: '';
Thanks!
There are two problems with your code:
The ::after selector works as a separate element, so having the transitions on the div won't work, they need to be applied to the ::after.
The :hover::after selector needs something to transition from.
This should work:
div {
position: relative;
display: inline-block;
}
img {
width: 100%;
height: 100%;
}
div::after {
-ms-transition: all 500ms ease-out 1s;
transition: all 500ms ease-out 1s;
position: absolute;
z-index: 1;
background-color: transparent;
opacity: 0.4;
left: 0;
top: 0;
height: 100%;
width: 100%;
content: '';
}
div:hover::after {
background-color: Indigo;
}
Somebody also shared this code with me, which seems to do the same thing by wrapping the image in a span class:
.imghov {
display: inline-block;
background-color: #fff;
-moz-transition: all 0.3s linear;
-ms-transition: all 0.3s linear;
-o-transition: all 0.3s linear;
-webkit-transition: all 0.13ss linear;
transition: all 0.3s linear;
}
.imghov img {
opacity: 1;
-moz-transition: all 0.3s linear;
-ms-transition: all 0.3s linear;
-o-transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
transition: all 0.3s linear;
}
.imghov:hover {
background-color: indigo;
-moz-transition: all 0.3s linear;
-ms-transition: all 0.3s linear;
-o-transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
transition: all 0.3s linear;
}
imghov:hover,
.imghov:hover img {
opacity: 0.6;
-moz-transition: all 0.3s linear;
-ms-transition: all 0.3s linear;
-o-transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
transition: all 0.3s linear;
}
CSS3 animation is not working for me in Safari (works ok in other browsers), I tried splitting out the shorthand so each property is declared separately eg:
-webkit-animation-name: glow;
-webkit-animation-duration: 2s;
......
But still doesn't work. Any ideas?
.light:after {
content:'';
display:block;
z-index:1;
border-radius: 50%;
width: 15px;
height: 15px;
position:absolute;
cursor:pointer;
background:rgba(64, 61, 51, 1);
-webkit-transition: all 500ms ease-in-out 0s;
-moz-transition: all 500ms ease-in-out 0s;
-o-transition: all 500ms ease-in-out 0s;
transition:all 500ms ease-in-out 0s;
}
.light.turned-on:after {
content:'';
display:block;
z-index:1;
background:rgba(255, 242, 204, 1);
-webkit-transition: all 500ms ease-in-out 0s;
-moz-transition: all 500ms ease-in-out 0s;
-o-transition: all 500ms ease-in-out 0s;
transition:all 500ms ease-in-out 0s;
}
.game-area.won .light:after {
-webkit-animation-name: glow;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: forwards;
-moz-animation: glow 2s ease-in-out infinite alternate;
-o-animation: glow 2s ease-in-out infinite alternate;
animation: glow 2s ease-in-out infinite alternate;
}
#-webkit-keyframes glow {
0% {
background: #FFF2CC;
}
10% {
background: #FFF2CC;
}
30% {
background: #C58FCC;
}
50% {
background: #AE86B2;
}
70% {
background: #B2A57D;
}
90% {
background: #B2FFEB;
}
100% {
background: #B2FFEB;
}
}
Just realized that in Safari 8.0.7 (10600.7.5) you cannot use animation on display: inline elements. Since display is inline-block or any other, animation works.
I hope it will help someone.
I have .css which makes mine image darker on hover:
a.darken {
display: inline-block;
background: #222222;
padding: 0;
}
a.darken img {
display: block;
-webkit-transition: all 0.5s linear;
-moz-transition: all 0.5s linear;
-ms-transition: all 0.5s linear;
-o-transition: all 0.5s linear;
transition: all 0.5s linear;
}
a.darken:hover img {
opacity: 0.1;
}
I wonder how could I change it that it would be darkened on normal state and would be normal on hover?
Move the opacity: 0.1 to the normal state and revert it to 1.0 on hover:
a.darken img {
display: block;
opacity: 0.1;
-webkit-transition: all 0.5s linear;
-moz-transition: all 0.5s linear;
-ms-transition: all 0.5s linear;
-o-transition: all 0.5s linear;
transition: all 0.5s linear;
}
a.darken:hover img {
opacity: 1.0;
}
Original Question... updated working code below:
I have a loading image which comes up during an ajax load event. The image shows/hides by adding or removing a "loading" class to the body element. Currently, the loading image animates background-size from 0 to 100%, and fades in the opacity (vice versa for the 'return' transition).
What I want to accomplish, though, is to have the background-size transition happen instantly (not transition) on the fade out, so:
Fade in: opacity from 0 to 1 in .2s, background size from 0 to 100% in .2s
Fade out: opacity from 1 to 0 in .2s, background size from 100% to 0 should happen instantly
#loader {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: -1;
opacity: 0;
-moz-opacity: 0;
transition: all .2s ease-in-out
}
#loader .image {
width: 400px;
height: 138px;
display: block;
position: absolute;
z-index: 2000;
top: 50%;
left: 50%;
margin: 0;
background: url(assets/images/loading.png) no-repeat;
background-size: 0 0;
transition: all .2s ease-in-out;
-webkit-animation: pulse 400ms ease-out infinite alternate;
-moz-animation: pulse 400ms ease-out infinite alternate;
-o-animation: pulse 400ms ease-out infinite alternate;
animation: pulse 400ms ease-out infinite alternate
}
.loading #loader {z-index: 1000; background-color: rgba(255,255,255,.7)}
.loading #loader .image {
background-size: 100% 100%;
margin: -69px 0 0 -200px;
transition: opacity .2s ease-in-out
}
I've changed transition property for this selector .loading #loader .image to "opacity" rather than "all", but it still performs the background-size transition.
Does anyone know how to achieve the different fade in and fade out transitions described above with css3? Thanks!
Updated Working Code
The issue was breaking out the individual properties (margin, background) into a comma separated list. I believe using transition: all will prevent you from being able to do different IN and OUT transitions.
#loader {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: -1;
opacity: 0;
-moz-opacity: 0;
.transition(opacity,.4s);
}
#loader .image {
width: 400px;
height: 138px;
display: block;
position: absolute;
z-index: 2000;
top: 50%;
left: 50%;
margin: 0;
background: url(assets/images/loading.png) no-repeat;
background-size: 0 0;
-webkit-transition: margin .4s ease-in-out;
-moz-transition: margin .4s ease-in-out;
-o-transition: margin .4s ease-in-out;
-ms-transition: margin .4s ease-in-out;
transition: margin .4s ease-in-out;
-webkit-animation: pulse 400ms ease-out infinite alternate;
-moz-animation: pulse 400ms ease-out infinite alternate;
-o-animation: pulse 400ms ease-out infinite alternate;
animation: pulse 400ms ease-out infinite alternate
}
.loading #loader {z-index: 1000; background-color: rgba(255,255,255,.7)}
.loading #loader .image {
background-size: 100% 100%;
margin: -69px 0 0 -200px;
-webkit-transition: background .4s ease-in-out, margin .4s ease-in-out;
-moz-transition: background .4s ease-in-out, margin .4s ease-in-out;
-o-transition: background .4s ease-in-out, margin .4s ease-in-out;
-ms-transition: background .4s ease-in-out, margin .4s ease-in-out;
transition: background .4s ease-in-out, margin .4s ease-in-out;
}
Here is a simplified test case:
div {
background: blue;
opacity: 0;
transition: opacity 2s ease-in-out;
}
div.loading {
opacity: 1;
background: red;
transition: opacity 2s ease-in-out, background 1s ease-in;
}
Notice how the opacity fades the same in and out, but the background only fades in, and immediately turns blue on fade out.
I used :hover as an example, but it should work the same when adding and removing classes with JavaScript.
Demo
If you'd like a more specific example please provide a reduced test case on dabblet or Jsfiddle.