简体   繁体   English

用JS重置CSS3计时功能

[英]Reset CSS3 timing function with JS

When the slide gets to the second "1", I need it to seamlessly reset to slide "2" and give the impression of infinite carousel, 当幻灯片到达第二个“ 1”时,我需要它无缝地重置为幻灯片“ 2”,并给人以无限旋转木马的印象,

The demo: 演示:

http://jsfiddle.net/benhowdle89/cWTbn/ http://jsfiddle.net/benhowdle89/cWTbn/

The code: 编码:

$('.wrapper li:first').clone().appendTo($('.wrapper ul'));
var element = $('.wrapper')[0];
element.setAttribute('data-left', 0);
setInterval(function() {
    var mL = +element.getAttribute('data-left'), t = +$('.wrapper').css('width').replace('px', ''), w = +$('.wrapper li:first').outerWidth();
    if(t == (Math.abs(mL) + w)){
        element.style.webkitTransitionTimingFunction = "none";
        element.style.webkitTransform = "none";
        element.setAttribute('data-left', 0);
    }
    element.style.webkitTransitionDuration = "0.3s";
    element.style.webkitTransitionTimingFunction = "ease-out";
    var currentL = +element.getAttribute('data-left');
    var newL = +(currentL + w);
    element.style.webkitTransform = "translate3d(-" + (newL) + "px, 0, 0)";
    element.setAttribute('data-left', newL);
}, 2000);

The problem: 问题:

After slide "1", it animates back to slide "2", so I need it not to, but to snap back to slide "2" (not visual to the user), 在幻灯片“ 1”之后,它会动画返回幻灯片“ 2”,因此我不需要这样做,而是要向后滑动到幻灯片“ 2”(对用户不可见),

Any ideas? 有任何想法吗?

Move the animation to a separate class. 将动画移到单独的类。 Since you're already using jQuery, you can use the following: 由于您已经在使用jQuery,因此可以使用以下代码:

$('.animiationClass').removeClass('animationClass').addClass('animationClass');

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

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