简体   繁体   English

jQuery Easing插件不宽松?

[英]jQuery Easing Plugin Not Easing?

I have no idea why this isnt working for me. 我不知道为什么这对我不起作用。 Maybe one of the jQuery Guru's out there can help me make this work! 也许其中一个jQuery Guru可以帮助我完成这项工作!

From the script below you can see that i have a UL block named five that i would like to ease to there anchor(#web). 从下面的脚本中你可以看到我有一个名为five的UL块,我想放松到那里锚(#web)。 When i click the menu item i do get the alert to activate so i think that part is correct. 当我点击菜单项时,我确实要启动警报,所以我认为该部分是正确的。

$(function() {
$('ul.five a').bind('click',function(event){
    var $anchor = $(this);
    alert('hellooo')
    $('html, body, section').stop().animate({
        scrollTop: $($anchor.attr('href')).offset().top
    }, 500,'easeInOutExpo');

    event.preventDefault();
});

}); });

This is what one of my sections looks like in case this would help? 这是我的一个部分看起来如果有帮助的话?

<section class="row divider-down" id="section1">
<header>
    <h1><img src="image/image1.png" alt="Alt"></h1>
    <p>some text</p>
</header>

Does anyone see anything that is obviously wrong here? 有没有人在这里看到任何明显错误的东西? Like i said the alert pops up but it doesnt "ease" down to the section? 就像我说的那样,警报弹出但它并没有“轻松”到该部分?

I think you were close. 我觉得你很亲密 Two things: 两件事情:

  1. Change what you are animating to $('body') 将你的动画改为$('body')
  2. You can't use 'easeInOutExpo' unless you have jQuery UI included (see EDIT below). 除非您包含jQuery UI,否则不能使用'easeInOutExpo'(请参阅下面的编辑)。

Try this: 尝试这个:

$(function() {
    $('ul.five a').bind('click',function(event){
        var $anchor = $(this);
        var $section = $($anchor.attr('href')); 
        if (!$section.length) { return; } // bail if there is no section

        $('body').stop().animate({ // only scroll the body
            scrollTop: $section.offset().top
        }, 500); // must remove 'easeInOutExpo' or include jQuery UI

        event.preventDefault();
    });
});

EDIT: FROM THE JQUERY DOCS: 编辑:来自JQUERY DOCS:

Easing 缓解

The remaining parameter of .animate() is a string naming an easing function to use. .animate()的其余参数是一个命名要使用的缓动函数的字符串。 An easing function specifies the speed at which the animation progresses at different points within the animation. 缓动函数指定动画在动画中的不同点处进行的速度。 The only easing implementations in the jQuery library are the default, called swing, and one that progresses at a constant pace, called linear. jQuery库中唯一的缓动实现是默认的,称为swing,以及一个以恒定速度进行的实现,称为线性。 More easing functions are available with the use of plug-ins, most notably the jQuery UI suite. 使用插件可以使用更多的缓动函数,尤其是jQuery UI套件。

So, you can't use 'easeInOutExpo' unless you have jQuery UI added on the page. 因此,除非您在页面上添加了jQuery UI,否则不能使用'easeInOutExpo'。

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

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