最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery - slideUp start fast and end slow? - Stack Overflow

programmeradmin4浏览0评论

I have a drop down menu which uses the slideUp feature in jQuery. I was wondering if I could remove the constant speed and start fast and end slow. I looked around and read about the easing method in animate, and I tried it, but it seems that it doesn't work for slideUp, only animate (if I am wrong please tell me); but otherwise, I cannot seem to figure it out. Any ideas? Here's my current code:

$(document).ready(function(){
    var h = "fast";

    $("[data-action='dropdown']").click(function(e) {
        e.stopPropagation();
    });

    $("body").click(function() {
        $("[data-action='dropdown'] ul ul").slideUp(h);
    });

    $("[data-action='dropdown'] ul li").click(function() {
        $("[data-action='dropdown'] ul ul").slideUp(h);

        $("ul", this).slideDown(h, function(){
            $("ul", this).slideUp(h);
        });
    });
});

The HTML is a very basic dropdown structure (just a ul element with lis and then inner uls nested inside. Then in css, I make it to where the inner ul ul is hidden with a display of none, then, of course, is toggled by jQuery).

Any help would be very much appreciated! :-)

I have a drop down menu which uses the slideUp feature in jQuery. I was wondering if I could remove the constant speed and start fast and end slow. I looked around and read about the easing method in animate, and I tried it, but it seems that it doesn't work for slideUp, only animate (if I am wrong please tell me); but otherwise, I cannot seem to figure it out. Any ideas? Here's my current code:

$(document).ready(function(){
    var h = "fast";

    $("[data-action='dropdown']").click(function(e) {
        e.stopPropagation();
    });

    $("body").click(function() {
        $("[data-action='dropdown'] ul ul").slideUp(h);
    });

    $("[data-action='dropdown'] ul li").click(function() {
        $("[data-action='dropdown'] ul ul").slideUp(h);

        $("ul", this).slideDown(h, function(){
            $("ul", this).slideUp(h);
        });
    });
});

The HTML is a very basic dropdown structure (just a ul element with lis and then inner uls nested inside. Then in css, I make it to where the inner ul ul is hidden with a display of none, then, of course, is toggled by jQuery).

Any help would be very much appreciated! :-)

Share Improve this question asked Dec 8, 2012 at 2:02 ModernDesignerModernDesigner 7,71711 gold badges36 silver badges42 bronze badges 7
  • 3 The .slideUp() method accepts an easing parameter, though there are only two easing options available in the core library. Did you read the doco? – nnnnnn Commented Dec 8, 2012 at 2:09
  • Yes, but it seems swing and linear isn't the type I'm looking for exactly... Is there any magical way I could transform or modify either swing or linear? – ModernDesigner Commented Dec 8, 2012 at 2:11
  • 2 You can use jQuery UI or some other easing plugin to get more options. – nnnnnn Commented Dec 8, 2012 at 2:11
  • Hmm, doesn't seem to work. I tried GSGD.co.uk's plugin but I looked in the error console and it says that the method I selected (easeOutBounce) is not defined, so I tried another, still undefined. – ModernDesigner Commented Dec 8, 2012 at 2:16
  • Okay, I see this alot on websites, it can't really be that hard! XP – ModernDesigner Commented Dec 8, 2012 at 2:21
 |  Show 2 more ments

1 Answer 1

Reset to default 6

We can use the jQuery easing plugin to do this.

Include the jQuery easing Javascript file:

https://cdnjs.cloudflare./ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js

Then we can use the easing variables as a parameter in the slideUp function.

Javascript

jQuery('#Example').slideUp({
    duration: 1000,
    easing: 'easeOutCubic'
});

Demo

发布评论

评论列表(0)

  1. 暂无评论