如何在三次貝塞爾方法上禁用 css3 過渡鼠標離開效果? (How to disable css3 transition mouseleave effect on cubic-bezier method?)


問題描述

如何在三次貝塞爾方法上禁用 css3 過渡鼠標離開效果? (How to disable css3 transition mouseleave effect on cubic-bezier method?)

I have a CSS3 rotate transform with a cubic-bezier transition-timing-function, it is working fine on mouse over, but i want to disable the mouseleave animation. I prepared a simple jsFiddle to show you.

img {
    transition : all 1s cubic-bezier(0.680,-0.550,0.265,1.550);
}

img:hover {
    transform: rotate(360deg);
}

參考解法

方法 1:

You mean you don't want it to transition back when you hover off? You can use an "infinite" (actually very large) transition-delay (that's the second time value in the shorthand) for that.

Like this:

demo

CSS:

img {
    transition: 0s 99999s; /* transition when mouse leaves */
}
img:hover {
    transform: rotate(360deg);

    /* transition on mouseover */
    transition: 1s cubic-bezier(0.680,-0.550,0.265,1.550);
}

Note that this will make the image rotate only on first hover.


If you want to make it rotate for each hover, then you'll have to use keyframe animations. Like this:

demo

CSS (no prefixes, you'll have to add them):

img:hover {
    animation: rot 1s cubic-bezier(0.680,-0.550,0.265,1.550);
}
@keyframes rot {
    to {
        transform: rotate(360deg);
    }
}


Also, I noticed that you were writing the unprefixed property first - you should always put it last. Especially now, when the coming versions of IE, Firefox and Opera are unprefixing transitions.

(by Barlas ApaydinAna)

參考文件

  1. How to disable css3 transition mouseleave effect on cubic-bezier method? (CC BY-SA 3.0/4.0)

#animation #css #transition #mouseleave #hover






相關問題

Iphone app PNG 序列動畫 - 如何在不崩潰的情況下以最佳方式使用 OPENgle (Iphone app PNG sequence animation - How to use OPENgle optimally without crashing)

jquery切換幻燈片和切換旋轉動畫 (jquery toggle slide and toggle rotation animate)

如何在三次貝塞爾方法上禁用 css3 過渡鼠標離開效果? (How to disable css3 transition mouseleave effect on cubic-bezier method?)

Android:故事書(動畫、聲音、圖片) (Android: Storybooks (animation, sounds, pictures))

JQuery 動畫凌亂 (JQuery Animations Messy)

拉斐爾對角變換對象和無限setIntervals (Raphael transform object diagonally and infinite setIntervals)

使用 mouseover 和 mouseout 時避免生澀的動畫 (Avoiding jerky animation when using mouseover and mouseout)

在 C 中復制 Spinrite 動畫效果 (Replicating Spinrite Animation Effect in C)

將樣式作為參數傳遞給 jquery animate (passing style as argument to jquery animate)

如何設置 UIButton 的圖像並隨後將其刪除(動畫) (How to setImage of a UIButton and subsequently remove it (animation))

單擊消息後的 MessageKit 動畫 (MessageKit animation after click on message)

連續貝塞爾動畫,不繼承變化時的緩動功能 (Continuous bezier animation without inheriting easing-function on change)







留言討論