简体   繁体   English

jQuery动画立即启动而不会放松

[英]jQuery Animation start immediately without easing

When using the following Jquery example in Chrome, the easing at the mouseenter event pauses the animation for a few moments. 在Chrome中使用以下Jquery示例时, mouseenter事件的缓动会暂停动画一会儿。 Is it possible to have the animation start immediately? 是否可以立即开始动画?

The desired effect is when mouseenter, move css left: -150 - 0; 预期的效果是当鼠标move css left: -150 - 0;时, move css left: -150 - 0; when mouseleave, move css left:(current position) to -150) 当鼠标move css left:(current position) to -150)时, move css left:(current position) to -150)

jQuery jQuery的

$(document).ready(function () {     
    $(".menuitem").on('mouseenter mouseleave', function( e ) {      
        $(".slider").stop().animate({left: e.type=="mouseenter"?0:-155}, 1000);   
    });
 })

html html

<div class='menuitem'>
    Test Menu Item
    <div class='slider'>Message about Item</div>
</div>    

css 的CSS

.slider {
    color: #FFF;
    position: absolute;
    left: -155px;
    width: 155px;
    top: 0px;
    height: 52px;
    transition: 1s;
    z-index: 10;
    border: 1px solid #bb0000;
    background: #bb0000;
    text-align: center;
}
.menuitem {
    float: left;
    overflow: hidden;
    position: relative;
    width: 155px;
    height: 52px;
    line-height: 52px;
    margin-left: 5px;
    line-height: 52px;
    background: #EEE;
    text-align: center;
}

JSFiddle 的jsfiddle

You have the delay set to 1 second. 您将延迟设置为1秒。

Lowering the ms to 100 will resolve this for you. 将ms降低到100将为您解决此问题。

$(document).ready(function () { $(document).ready(function(){

$(".menuitem").on('mouseenter mouseleave', function( e ) {
    // Find Slide element.

    $(".slider").stop().animate({left: e.type=="mouseenter"?0:-155}, 100);   
});

}) })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM