简体   繁体   English

使用jQuery缓动插件的jQuery双重动画

[英]jQuery double animation using the jquery easing plugin

I want to implement something like this page does: link 我想实现类似于此页面的功能: 链接

Look at the Clicker box. 查看“ Clicker”框。 The box has two animations going on. 盒子上有两个动画。 One for the easeInQuad, then the other animation is for the easeInOutSine. 一个用于easyInQuad,然后另一个动画用于easyInOutSine。

How can I implement something like that in my own function? 如何在自己的函数中实现类似的功能?

$(function() 
{
    var iH = window.innerHeight + 80;
    var position = $(window).scrollTop();

    $(window).scroll(function() 
    {
        var scroll = $(window).scrollTop();

        if(scroll > position) 
        {
            $("body").animate(
            {
                scrollTop: iH
            },1000,
            "easeInOutQuart")
            .animate(
            {
                scrollTop: parseInt($(window).scrollTop()) - 80
            },1000,
            "easeInOutQuart");
        } 
        else if(scroll < position) 
        {
            $("body").get(0).scrollTop = 0;
        }

        position = $(window).scrollTop();
    });
});

The second animate doesn't work quite well. 第二个动画效果不佳。 But it does scroll it up. 但是它确实向上滚动。 But it scroll it up too much not just 80 pixels. 但它会向上滚动太多,而不仅仅是80像素。 It scroll it up to the top, then the animation gets into an infinite loop. 它将其向上滚动到顶部,然后动画进入无限循环。 After the second .animate it will continue to animate it again and again and again. 在第二次.animate之后,它将继续一次又一次地对其进行动画处理。 Non stop. 不间断。

I think its better to use a toggle effect 我认为最好使用切换效果

http://www.sohtanaka.com/web-design/examples/toggle/ http://www.sohtanaka.com/web-design/examples/toggle/

$("body").stop(true) $(“ body”)。stop(true)

This will clear all animation Queues on the object. 这将清除对象上的所有动画队列。

http://docs.jquery.com/Effects/stop http://docs.jquery.com/Effects/stop

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

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