[英]jquery hover function with CSS transition effect ONLY working on second hover
很奇怪。 下面的代碼僅適用於第二次懸停。 例如,頁面已加載,切換有效,但過渡動畫直到每次兩次都始終保持一致才起作用 。
jQuery的 :
$('.greenBox').hover(function(){
$(this).addClass('expanded');
$(this).removeClass('contracted');
}, function(){
$(this).removeClass('expanded');
$(this).addClass('contracted');
});
CSS :
.greenBox {
background-image: url("../images/background_bubble.png");
background-repeat: no-repeat;
// transition:max-height .5s linear;
// background: linear-gradient(#69af38, #8fba35);
transition: .8s;
color: #FFF;
width: 310px;
height: 137px;
position: relative;
overflow:hidden;
z-index: 2;
display: block;
// -moz-transition: background-color 0.5s ease, height 0.5s ease, bottom 0.5s ease;
// -o-transition: background-color 0.5s ease, height 0.5s ease, bottom 0.5s ease;
// -webkit-transition: background-color 0.5s ease, height 0.5s ease, bottom 0.5s ease; /* Chrome 1-25, Safari 3.2+ */
// transition: background-color 0.5s ease, height 0.5s ease, bottom 0.5s ease;
overflow: hidden;
bottom: 7px;
// -webkit-clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 60% 75%, 49% 86%, 37% 75%, 0% 75%);
// clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 60% 75%, 49% 86%, 37% 75%, 0% 75%);
.noLink {
color: #FFF;
&:hover {
cursor: auto;
color: #FFF;
background: linear-gradient(#69af38, #8fba35);
}
}
}
和。
.contracted {
// transition: 11s;
max-height: 150px;
overflow:hidden;
}
和。
.expanded {
height: auto;
min-height:150px;
max-height:750px;
// transition: 11s;
// margin-top:5px;
// 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;
background: -webkit-linear-gradient(#812990, #9E248E);
}
您需要確保元素以contracted
類開頭。 在我補充說之前,它對我也只適用於第二次懸停。
小提琴: http : //jsfiddle.net/AtheistP3ace/czrqkorn/
<div class="greenBox contracted"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.