Reputation: 1377
I want to change the size of an HTML element on mouse over. It works in general. However, at least in Firefox, it creates an ugly flicker effect, when the mouse is right at the bottom edge of the DIV: the browser will then keep resizing even if the mouse is not moved at all. Is there anything I can do about that?
.my-hover-square {
width: 240px;
height: 240px;
position: absolute;
display: -webkit-inline-box;
-webkit-transition: height 1s;
/* Safari */
transition: height 1s;
-webkit-transition: width 1s;
/* Safari */
transition: width 1s;
background: pink;
}
.my-hover-square:hover {
width: 450px;
height: 200px;
}
<div class="my-hover-square"></div>
Upvotes: 0
Views: 1336
Reputation: 38
You could wrap it:
.hover-container {
min-width: 240px;
height: 240px;
}
.hover-container>.my-hover-square {
width: 240px;
height: 240px;
position: absolute;
display: -webkit-inline-box;
-webkit-transition: height 1s;
/* Safari */
transition: height 1s width 1s;
-webkit-transition: width 1s;
/* Safari */
transition: width 1s;
background: pink;
}
.hover-container:hover>.my-hover-square {
width: 450px;
height: 200px;
}
<div class="hover-container">
<div class="my-hover-square"></div>
</div>
Upvotes: 2
Reputation:
For me, it's freaking out because you're changing the height of the div, which moves it away from the mouse pointer, which removes the :hover pseudo class, which results in the div resizing, which moves it back under the mouse pointer, which adds the :hover pseudo class. Rinse and repeat. I don't think it's possible to keep the resize and not have this happen using pure css.
.my-hover-square {
width: 240px;
height: 240px;
position: absolute;
display: -webkit-inline-box;
-webkit-transition: height 1s;
/* Safari */
transition: height 1s;
-webkit-transition: width 1s;
/* Safari */
transition: width 1s;
background: pink;
}
.my-hover-square:hover {
width: 450px;
}
<div class="my-hover-square"></div>
Upvotes: 1
Reputation: 115285
You need to combine them:
transition: height 1s, width 1s;
.my-hover-square {
width: 240px;
height: 240px;
transition: height 1s, width 1s;
background: pink;
}
.my-hover-square:hover {
width: 450px;
height: 200px;
}
<div class="my-hover-square"></div>
Upvotes: 3
Reputation: 10274
.my-hover-square {
width: 240px;
height: 240px;
position: absolute;
display: -webkit-inline-box;
/* -webkit-transition: height 1s;
Safari
transition: height 1s;
-webkit-transition: width 1s;
Safari
transition: width 1s;
*/
transition: width 1s, height 1s;
-webkit-transition: width 1s, height 1s;
background: pink;
}
.my-hover-square:hover {
width: 450px;
height: 200px;
}
<div class="my-hover-square"></div>
If you write transition: height 1s;
and write transition: width 1s;
, it's duplicate.
So only transition: width 1s;
can be active.
When you want to use multiple attribute with transition
,
You shoulde use like this transition: width 1s, height 1s, ...;
Upvotes: 2