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

  • Home
  • SEARCH
  • 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 8101835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:05:10+00:00 2026-06-05T23:05:10+00:00

I developed a simple jQuery animation first and later I create a jQuery function

  • 0

I developed a simple jQuery animation first and later I create a jQuery function for reusability which will do the same thing. Here is a demo: http://jsfiddle.net/SpMns/

My code is working but not reliably so: when I click on the button to run the code, nothing happens; clicking it two or three times will start the animation. Why wouldn’t it work the first time?

Please have a look at my routine and tell me which area I need to rectify:

jQuery.fn.busyToggle = function(ImgLoadSrc, marginBottom, opacity, speed, 
                                easing, callback) {
  var oDiv = $("<div id='BusyBox'><img src='" + ImgLoadSrc 
           + "'  alt='Loading...'/><div><em>Loading Wait...</em></div></div>");
  if ($("#BusyBox").exists() == false) {
    //alert('div not exist');
    oDiv.css("background", "-moz-linear-gradient(center top , #F1F2F2 0%, #F1F2F2 100%) repeat scroll 0 0 transparent");
    oDiv.css("border-top-left-radius", "5px");
    oDiv.css("border-top-right-radius", "5px");
    oDiv.css("bottom", "0px");
    oDiv.css("font-size", "0.8em");
    oDiv.css("font-style", "normal");
    oDiv.css("font-weight", "normal");
    oDiv.css("left", "50%");
    oDiv.css("margin-left", "-45px");
    oDiv.css("padding-top", "20px");
    oDiv.css("position", "fixed");
    oDiv.css("text-align", "center");
    oDiv.css("width", "90px");
    oDiv.css("height", "50px");
    oDiv.css("margin-bottom", "-70px");
    oDiv.css("background-repeat", "no-repeat");
    oDiv.css("background-position", "center center");
    oDiv.data('IsUp', 1)
    oDiv.appendTo('body');
  }

  // i work with jquery data function for achieving toggle behaviour
  if (oDiv.data('IsUp') == 1) {
    oDiv.data('IsUp', 0);
    return this.stop(true).animate({
      marginBottom: marginBottom,
      opacity: opacity
    }, {
      queue: false,
      duration: speed,
      complete: callback
    });
  }
  else {
    oDiv.data('IsUp', 1);
    return this.stop(true).animate({
      marginBottom: marginBottom,
      opacity: opacity
    }, {
      queue: false,
      duration: speed,
      complete: callback
    });
  }
};
$(document).ready(function() {
  $("#Process").click(function() {
    if (flag == 1) {
      $('#BusyBox').busyToggle('images/loader.gif', 0, 1, 500, 0, function() {
        alert('div visible')
      });
      flag = 0;
    }
    else {
      $('#BusyBox').busyToggle('images/loader.gif', -70, 0, 500, 0, function(){
        alert('div hide')
      });
      flag = 1;
    }
    return false;
  });
});

What could be causing this to fail the first time it’s run?

  • 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-05T23:05:12+00:00Added an answer on June 5, 2026 at 11:05 pm

    The problem are is the this usage in the #busyToggle

    On the first call $(‘#BusyBox’) becomes an empty Array, which means that this (in #busyToggle) is also empty Array.

    A better solution to your probelm would be to call busyToggle this way:

    $('#Process').busyToggle('images/loader.gif', 0, 1, 500, 0, function() {
        alert('div visible')
    });
    

    and use $(‘#BusyBox’) instead of this in your function.

    You can find all the code over there: http://jsfiddle.net/ubmCt/8/

    P.S: I’ve also added following line to the ready function, otherwise it won’t run in most browsers

    var flag = 1;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've developed a very simple ASP.NET (jQuery) application. The RDBMS is MS Sql Server
I developed one Simple app, which contains one textview.and my problem is that I
I have developed a simple location aware iPhone application which is functionally working very
I have started learning MVC2. I developed a simple customer search screen with Jquery
I've just developed a simple page, using the standard jQuery tabs jQuery Tabs Link
I have a simple app developed with jQuery Mobile and implemented in PhoneGap. It
I developed a simple jquery ajax php application. I done a pagination. In that
I created a simple a jQuery function that is to be used for developer
I am using jQuery UI (1.8.16) extensively in my application. I've developed a simple
I developed one simple app, like subtraction, addition. In this app I use three

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.