Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:01:54+00:00 2026-06-14T19:01:54+00:00

I am trying to imitate the jQuery animate() method to strip out the opacity

  • 0

I am trying to imitate the jQuery animate() method to strip out the opacity style for unsupported browsers (Internet Explorer of course)!

However, I am struggling to imitate the parameters that the jQuery animate() method accepts.

According to the jQuery documentation:

.animate( properties [, duration] [, easing] [, complete] )
.animate( properties, options )

What I would like to know is how does the function know whether parameter 2 is the duration or the options…?

Notice the three arguments here:

$('#test').animate({opacity:0},200,function(){
    $(this).hide(); 
});

But I can also execute the same function like this (notice the easing parameter):

$('#test').animate({opacity:0},200,'swing',function(){
    $(this).hide(); 
});

How does the function know that the third parameter is a string, not a function?

Surely this is not done like so????

if(typeof parameter1=='string'){
    // and so on
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:01:55+00:00Added an answer on June 14, 2026 at 7:01 pm

    Surely this is not done like so????

    if(typeof parameter1=='string'){
        // and so on
    }
    

    Yes, that is exactly how it is done.


    From the jQuery source:

    var opt = speed && typeof speed === "object" ? jQuery.extend({},
    speed) : {
        complete: fn || !fn && easing || jQuery.isFunction(speed) && speed,
        duration: speed,
        easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
    };
    
    opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration : opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[opt.duration] : jQuery.fx.speeds._default;
    

    Can be rewritten to be more readable this way:

    var opt = { };
    
    if (typeof speed == 'object')
        opt = jQuery.extend({ }, speed);
    else {
    
        if (fn)
            opt.complete = fn;
        else if (easing)
            opt.complete = easing;
        else if (jQuery.isFunction(speed))
            opt.complete = speed;
    
        opt.duration = speed;
    
        if (fn && easing)
            opt.easing = easing;
        else if (easing && !jQuery.isFunction(easing))
            opt.easing = easing;
    
    }
    
    if (jQuery.fx.off)
        opt.duration = 0;
    else if (typeof opt.duration === 'number')
        opt.duration = opt.duration;
    else if (opt.duration in jQuery.fx.speeds)
        opt.duration = jQuery.fx.speeds[opt.duration];
    else
        opt.duration = jQuery.fx.speeds._default;
    

    Update

    If you want an easier way to take care of this logic for you, candy provides a neat Array helper called persuade. This function allows you to pass in an array (or arguments) object with a list of types. You will be returned an array with the arguments organized by the types. It’s an easy way to deal with polymorphic parameters:

    function foo(/* duration, easing, complete */) {
        var args = candy.Arrays.persuade(arguments, [ 'number', 'string', 'function' ]);
        var duration = args[0], easing = args[1], complete = args[2];
        console.log(duration, easing, complete);
    }
    
    foo('test');
    // => undefined, 'test', undefined
    
    foo(2, function() { });
    // => 2, undefined, function() { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically what I am trying to do is to imitate the replace button with
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to figure out how I can do this properly. The print_r looks like
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
trying to figure out why this is happening - I have an input text
I'm trying to create my custom toolbox which imitates jQuery's design pattern. Basically, the
I am trying to imitate this tutorial about creating a simple Apple-themed breadcrumb found
I'm trying to subclass a NSCollectionView which imitate the behaviors of UITableView as Twitter
I'm trying to program two buttons to imitate the up/down arrow key behavior, meaning

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.