I'm trying to disable the transition delay by adding a class that put the value of the delay to 0 seconds.
I don't now why it doesn't work.
The only thing that worked for me was to add the .no-anim class transition: none; but than there is no animation at all.
I want to keep the animation also after clicking the button that add the class so the solution with the transition: none; is not good enough in my case...
Any idea?
$('.button').click(function(){
$this = $('.box');
$this.addClass('no-anim');
setTimeout(function() {
$this.removeClass('no-anim');
}, 3000);
});
.box {
width: 200px;
height: 200px;
background: #333;
transition: width .3s ease-in-out;
position: relative;
}
.box:hover {
width: 300px;
transition-delay: 2.5s;
}
.box.no-anim {
transition-delay: .3s;
}
.button {
display: inline-block;
height: 50px;
width: 30px;
background: #ff3434;
position: absolute;
right: 0;
top: 50%;
margin-top: -25px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="box">
<span class="button"></span>
</div>
The selector .box.no-anim has the same precedence as a plain .box selector (they're both just classes). That means that .box.no-anim's addition of the :hover pseduo-selector is giving it a higher precendence, making it override your no-anim transition-delay.
Add :hover to your .no-anim selector as well and it will work correctly.
$('.button').click(function(){
$this = $('.box');
$this.addClass('no-anim');
setTimeout(function() {
$this.removeClass('no-anim');
}, 3000);
});
.box {
width: 200px;
height: 200px;
background: #333;
transition: width .3s ease-in-out;
position: relative;
}
.box:hover {
width: 300px;
transition-delay: 2.5s;
}
.box.no-anim:hover {
transition-delay: .3s;
}
.button {
display: inline-block;
height: 50px;
width: 30px;
background: #ff3434;
position: absolute;
right: 0;
top: 50%;
margin-top: -25px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="box">
<span class="button"></span>
</div>
Related
I want to achive a simple animation on hover in css, but while hovering off, the animation jumps and makes it look silly. Is there a way to avoid that?
My wish would be that it is colapsing the same way it originaly transformed.
Codepen: https://codepen.io/misah/pen/abzRXvL
.item {
width: 20%;
height: 0;
padding-top: 20%;
background-color: blue;
position: relative;
transition: 800ms;
}
.item::after {
position: absolute;
bottom: 0;
height: 30%;
width: 100%;
content: "";
background-color: grey;
transition: transform 800ms ease-in-out;
}
.item:hover::after {
transform: scaleY(2);
transform-origin: bottom;
}
<div class="item">
</div>
This happens because the transform-origin: bottom; is only applied when the item is hovered. When not hovered it falls back to the default - center. Move the rule to the declaration of the ::after.
.item {
width: 20%;
height: 0;
padding-top: 20%;
background-color: blue;
position: relative;
transition: 800ms;
}
.item::after {
position: absolute;
bottom: 0;
height: 30%;
width: 100%;
content: "";
background-color: grey;
transition: transform 800ms ease-in-out;
transform-origin: bottom;
}
.item:hover::after {
transform: scaleY(2);
}
<div class="item"></div>
This question already has answers here:
Is there a "previous sibling" selector?
(30 answers)
How to affect other elements when one element is hovered
(9 answers)
Closed 4 years ago.
I'm trying to transition the opacity of 2 background images in 2 separate divs while hovering over a 3rd using HTML and CSS. Seems fairly straight forward but I have had no luck searching everything I can on hover targets including not:hover, parents siblings etc. Here is a link to my codepen example. My goal is to affect the opacity of box 1 & 2 by only hovering box 3 (blue box) and reverting back on hover out. All suggestions on restructuring and/or styling are welcome. Thanks.
https://codepen.io/NikoVanDam/pen/Ygzjpz
HTML
<body>
<div class="Container">
<div class="Box1"></div>
<div class="Filler1"></div>
<div class="Box2"></div>
<div class="Filler2"></div>
<div class="Box3"></div>
</div>
</body>
CSS
.Container {
width: 383px;
height: 404px;
background: yellow;
float: left;
}
.Box1 {
width: 383px;
height: 210px;
background: red;
float: left;
opacity: 0.2;
transition: opacity 0.5s ease-in-out;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
}
.Filler1 {
width: 130px;
height: 194px;
background: grey;
float: left;
}
.Box2 {
width: 253px;
height: 110px;
background: blue;
float: left;
Opacity: 0.2;
transition: opacity 0.5s ease-in-out;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
}
.Filler2 {
width: 160px;
height: 84px;
background: grey;
float: left;
}
.Box3 {
width: 93px;
height: 84px;
background: blue;
float: left;
}
Unfortunately, there's no pure CSS way to accomplish this as .Box3:hover comes after the elements you're wishing to target. Here's a straightforward JavaScript approach as a consolation prize.
const box3 = document.querySelector('.Box3');
const container = document.querySelector('.Container');
box3.addEventListener("mouseover", handleMouseOver);
box3.addEventListener("mouseout", handleMouseOut);
function handleMouseOver() {
container.classList.add('hover');
}
function handleMouseOut() {
container.classList.remove('hover');
}
.Container {
width: 383px;
height: 404px;
background: yellow;
float: left;
}
.Box1 {
width: 383px;
height: 210px;
background: red;
float: left;
opacity: 0.2;
transition: opacity 0.5s ease-in-out;
}
.Filler1 {
width: 130px;
height: 194px;
background: grey;
float: left;
}
.Box2 {
width: 253px;
height: 110px;
background: blue;
float: left;
Opacity: 0.2;
transition: opacity 0.5s ease-in-out;
}
.Filler2 {
width: 160px;
height: 84px;
background: grey;
float: left;
}
.Box3 {
width: 93px;
height: 84px;
background: blue;
float: left;
}
.hover .Box1,
.hover .Box2 {
opacity: .7;
}
<body>
<div class="Container">
<div class="Box1"></div>
<div class="Filler1"></div>
<div class="Box2"></div>
<div class="Filler2"></div>
<div class="Box3"></div>
</div>
</body>
You have to use javascript what you want, here a snippet,
(function() {
var container = document.querySelector('.Container');
var hoverBox = document.querySelector('.hover-box');
hoverBox.addEventListener('mouseover', function(){
container.classList.add('hovered');
});
hoverBox.addEventListener('mouseout', function(){
container.classList.remove('hovered');
});
})();
.Container {
width: 383px;
height: 404px;
background: yellow;
float: left;
}
.color-box {
float: left;
opacity: 0.2;
transition: opacity 0.5s ease-in-out;
}
.gray-box {
background: grey;
float: left;
}
.Box1 {
width: 383px;
height: 210px;
background: red;
}
.Filler1 {
width: 130px;
height: 194px;
}
.Box2 {
width: 253px;
height: 110px;
background: blue;
}
.Filler2 {
width: 160px;
height: 84px;
}
.Box3 {
width: 93px;
height: 84px;
background: blue;
float: left;
}
.hover-box {
cursor: pointer;
}
.hovered .color-box{
opacity: .7
}
<body>
<div class="Container">
<div class="Box1 color-box"></div>
<div class="Filler1 gray-box"></div>
<div class="Box2 color-box"></div>
<div class="Filler2 gray-box"></div>
<div class="Box3 hover-box"></div>
</div>
</body>
Since I am a beginner, I am really struggling with this.
Can you tell me how I can transition the position of the .box when hovering?
I could only display it, but I couldn't transition the position from bottom to top which is what I want to do.
.more {
position: relative;
height: 100px;
}
.box {
display: none;
position: absolute;
background: white;
border-radius: 4px;
height: 43px;
width: 169px;
top: 50px;
transition: top 5s;
}
.more:hover .box {
top: 100px;
display: block;
}
<div class="col-sm-1 more">
More
<div class="box">
<span>Pages</span>
</div>
</div>
Try visibility instead of display. Visibility works a bit better with transitions.
.more {
position: relative;
height: 100px;
}
.box {
position: absolute;
background: white;
border-radius: 4px;
height: 43px;
width: 169px;
top: 50px;
transition: top 5s ease;
visibility: hidden;
}
.more:hover .box {
top: 100px;
display: block;
opacity: 1;
visibility: visible;
}
<div class="col-sm-1 more">
More
<div class="box">
<span>Pages</span>
</div>
</div>
Transition works by interpolating between the old value and then new value. The issue that you're seeing here is technically the old value was never applied in the first place.
Setting .box to display: none was basically saying, "don't render this at all," and transition can't transition between something that doens't exist and another value. Using visibility instead of display fixes the issue since visibility: hidden only hides the element, not removing it completely.
.more {
position: relative;
height: 100px;
}
.box {
visibility: hidden;
position: absolute;
background: white;
border-radius: 4px;
height: 43px;
width: 169px;
top: 50px;
transition: top 5s;
}
.more:hover .box {
top: 100px;
visibility: visible;
}
<div class="col-sm-1 more">
More
<div class="box">
<span>Pages</span>
</div>
</div>
If you want the transition to work in reverse, then you can add another transition delaying the visibility.
Try this :
you can easily change the margin in the box class if you want and the speed in the transition :)
.box {
position:absolute;
top:0;
margin-top:400px;
}
.more:hover .box {
margin-top:0;
-moz-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
I'm having trouble using the ease function in CSS.
I have an image and when you hover over it I want it to ease to get bigger and show another div.
<div class="info1">
<img src="info.png">
<div class="infoh">
<p>Information to be shown when hovered over</p>
</div>
</div>
The CSS
.infoh {
width: 180px;
height: 180px;
display: none;
position: absolute;
background-color: #ffb534;
padding: 30px;
border-radius: 100%;
-moz-border-radius: 100%;
-webkit-border-radius: 100%;
border: 4px solid #ffffff;
z-index: 1;
margin-left: -80px;
margin-top: -33px;
}
.infoh p {
font-size: inherit;
text-align: center;
}
.info1:hover .infoh {
display: block;
}
.info1 {
position: absolute;
display: inline-block;
width: 32px;
height: 32px;
margin-left: 19.5%;
margin-top: -1.5%
}
I tried placing it on the image but that didn't work, then I tried on each div, and couldn't get it to ease. It just pops up.
.info1 img {
-webkit-transition: width 2s; /* Safari */
transition: width 2s;
transition-timing-function: ease;
-webkit-transition-timing-function: ease;
}
I'm not exactly sure of the effect you're after, but as #Paulie_D said, you're probably looking at using visibility and opacity.
Here's some code to try out, and at least that should give you something to work with.
(I also changed the order of your HTML a bit)
.info1 {
position: absolute;
display: inline-block;
width: 32px;
height: 32px;
}
.info1 img {
width: 32px;
height: 32px;
-webkit-transition: all 2s; /* Safari */
transition: all 2s;
transition-timing-function: ease;
-webkit-transition-timing-function: ease;
}
.infoh {
position: absolute;
visibility: hidden;
opacity: 0;
z-index: 1;
width: 180px;
height: 180px;
background-color: #ffb534;
padding: 30px;
border-radius: 100%;
-moz-border-radius: 100%;
-webkit-border-radius: 100%;
border: 4px solid #ffffff;
-webkit-transition: all 1s; /*Safari*/
transition: all 1s;
}
.infoh p {
font-size: inherit;
text-align: center;
}
.info1:hover img {
width: 300px;
height: 300px;
}
.info1:hover .infoh {
visibility: visible;
opacity: 1;
-webkit-transition-delay: 1s; /*Safari*/
transition-delay: 1s;
}
<div class="info1">
<div class="infoh">
<p>Information to be shown when hovered over</p>
</div>
<img src="https://unsplash.it/300/300">
</div>
Hope this helps, and good luck!
Is it possible to add an opacity transition to CSS3 div overlay target?
JSFIDDLE: http://jsfiddle.net/pb7St/
#content {
background-color: #ccc;
height: 300px;
width: 300px;
z-index:1;
}
.overlaystyle {
height: 100px;
width: 100px;
background-color: #000;
left: 20px;
top: 20px;
position: absolute;
z-index:2;
opacity: 0;
-webkit-transition: opacity 1s ease;
}
#overlay {
display:none;
}
#overlay:target {
display:block;
opacity: 1;
}
Is there any other (better) way to close / hide the div? Currently I'm using:
href="#_"
Yes, there is:
JSFiddle Demo
CSS
.overlaystyle {
height: 100px;
width: 100px;
background-color: #000;
left: 20px;
top: 20px;
position: absolute;
z-index:2;
opacity: 0;
-webkit-transition: opacity 1s ease, visibility 1s 0s; /* added visibility transition */
}
#overlay {
//display:none;
visibility:hidden
}
#overlay:target {
//display:block;
visibility:visible;
opacity: 1;
}
EDITED to add transition to visibility with delay for fade-out effect. Personally, I'd go with JQuery. :)