2016-07-14 3 views
0

지연 값을 0 초로 설정하는 클래스를 추가하여 전환 지연을 비활성화하려고합니다.CSS 전환 지연 사용 안함

지금은 작동하지 않습니다.

나를 위해 유일한 것은 .no-anim 클래스 transition: none;을 추가했지만 전혀 애니메이션이없는 것입니다.

나는 transition: none;과 솔루션은 내 경우에는 충분하지 않습니다 있도록 클래스를 추가 버튼을 클릭 한 후도 애니메이션을 유지하려는

...

어떤 생각?

$('.button').click(function(){ 
 
\t $this = $('.box'); 
 
\t $this.addClass('no-anim'); 
 
    setTimeout(function() { 
 
    \t $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>

답변

0

선택기 .box.no-anim는 일반 .box 선택 (그들은 모두 단지 클래스이야)와 같은 우선 순위를 갖습니다. 즉 .box.no-anim:hover pseduo-selector가 추가되어 더 높은 우선 순위를 갖게되어 no-anim 전환 지연보다 우선합니다.

또한 .no-anim 선택기에 :hover을 추가하면 제대로 작동합니다.

$('.button').click(function(){ 
 
\t $this = $('.box'); 
 
\t $this.addClass('no-anim'); 
 
    setTimeout(function() { 
 
    \t $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>

+0

는 당신을 위해 작동하고 나는 또한이 솔루션을 시도했다가 여기 https://jsfiddle.net/6qk5tmv3/ 크롬 (51)에 자신을 일을 볼 수없는 이유는 무엇입니까? –

+0

@MatanG. 코드 스 니펫에서 해봤습니까? 거기에서 잘 작동합니다. 당신의 바이올린에 뭔가가 엉망이긴하지만 여기 [잘 작동합니다 ...] (https://jsfiddle.net/6qk5tmv3/3/) – Harangue

+0

도와 주셔서 감사드립니다. 나는 아직도 그것을 볼 수 없다. 상자에'.no-anim' 클래스가없는 동안 빨간 버튼을 클릭하면'.box.no-anim : hover'에서 설정 한 것과 같이 지연 시간은 2.5 초가되고 0.3 초가 아닙니다. .. –