$('.greenBox').hover(function(){
$(this).addClass('expanded');
$(this).removeClass('contracted');
}, function(){
$(this).removeClass('expanded');
$(this).addClass('contracted');
}); // end of hover state for green box
Wondering if there is a way to implement a transition with the above jquery logic? Between the adding or removing of the class.
I have tried the below, but it did not work: (It is a simple div small height > large height toggle)
.expanded {
height: auto;
// to make the box move up add back the bottom 300px
// bottom: 300px;
background: linear-gradient(#812990, #9e248e);
-webkit-transition-timing-function: linear;
transition-timing-function: linear;
}
also:
.contracted {
height: 100px;
}
.contractedclass look like?autovalues in CSS. Also you need both states for a transition to work and you haven't set atransitionproperty. More infotransitionsetting in your CSS. Although, as @LuudJacobs says you cannot transition from/toheight: autoso you would need to deal in concrete sizes. Here's a working CSS-only demo: jsfiddle.net/76n6Luc8