Andrew
Andrew

Reputation: 12442

Can I make jQuery's load(); appear slowly?

jQuery code:

$(document).ready(function() {
  $("#post_submit").click(function(event) {
      event.preventDefault();
    $("#show").load("post.php", {
      submit: $("#post_submit").val(),
      title: $("#title").val(),
      body: $("#body").val(),
      tags: $("#tags").val()
    });
  });
});

This works fine, and the information is displayed in without the page reloading (yay), but it's not very smooth. I was wondering how I could make it appear slowly, like $(div).show("slow"); or $(div).toggle("slow").

Upvotes: 0

Views: 2048

Answers (1)

Jon Winstanley
Jon Winstanley

Reputation: 23321

The way to do this would be to load the new content into a hidden container. Then, chain a show('slow') to the end of the load event.

As shown in the jQuery documentation, load returns the jQuery object, so it can be chained with other events.

Something along the lines of

$("#show").hide();
$("#show").load("post.php", {
  submit: $("#post_submit").val(),
  title: $("#title").val(),
  body: $("#body").val(),
  tags: $("#tags").val()
}).show("slow");

Upvotes: 2

Related Questions