1

Possible Duplicate:
How to show loading spinner in jQuery?

I have a div that has a lot of stuff in it, and doesn't load into the DOM smoothly. Is there a way I could add a spinner kind of like you see in AJAX calls? Here is my current code.

<h4>Network Printers</h4>
<div id="demo1" class="demo">
    <ul class="printer-tree">
        <li>Many List Items</li>
    </ul>
</div>
<div class="spinner" style="display:none;"></div>
$(function () {
    $("#demo1").jstree({ 
        "plugins" : [ "themes", "html_data", "checkbox", "sort", "ui" ]
    });
});
Community
  • 1
  • 1
ndesign11
  • 1,652
  • 3
  • 19
  • 34

2 Answers2

2

according to the documentation, you can bind an event to the tree creation, like this:

$(function () {

    $("div.spinner").show();

    $("#demo1").bind("loaded.jstree", function (event, data) {
        // tree has been loaded
        $("div.spinner").hide();
    }).jstree(
        { 
            "plugins" : [ "themes", "html_data", "checkbox", "sort", "ui" ]
        }
    );

});
Reinder Wit
  • 6,174
  • 1
  • 24
  • 32
0

I guess you can!

First, your syntax seem to be invalid. The opening tag of your div doesn't gets closed; You are missing a >.

You could enable the spinner on default, and disable it whenever the content is loaded using a callback. I'm don't know anything about jstree but according to it's documentation you can set a callback in some methods.

Tim S.
  • 12,449
  • 7
  • 41
  • 68