简体   繁体   English

jQuery动画步变换

[英]jQuery animate step transform

I am facing problem with jQuery animate now property. 我现在使用jQuery animate属性遇到问题。 But it's always increment current value. 但是它总是增加当前值。 i want it will start from 0 and will end at 20 every time in loop. 我希望它从0开始,每次循环都在20结束。 Here is my code 这是我的代码

 var container = $('#top_slides'); var items = container.children('.top_slide_sp'); var lengths = items.length; var index = 0; var transition_speed = 5000; var transSP = function(){ items.eq(index).animate({ 'opacity': '100', now: '+=20' }, { step: function (now, fx) { $(this).css('transform', "translate3d(" + now + "px, 0, 0)"); }, duration: 6000, easing: 'linear', queue: false }, 'linear'); }; var show = function(){ items.eq(index).fadeOut(800, function(){ index += 1; if (index === lengths) { index = 0; } transSP(); items.eq(index).fadeIn(800, function(){ items.removeClass('active'); items.eq(index).addClass('active'); setTimeout(show, transition_speed); }); }); }; // Show first item items.eq(index).addClass('active').fadeIn(400, function () { transSP(); setTimeout(show, transition_speed); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="top_slides"> <div class="top_slide_sp">1</div> <div class="top_slide_sp">2</div> <div class="top_slide_sp">3</div> </div> 

Your current code the plus(+) was the problem 您当前的代码加号(+)是问题

{
            'opacity': '100',
             now: '+=20' <--------
}

Remove and lets try like this 删除并让这样尝试

{
            'opacity': '100',
             now: '=20'
        }

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

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