开发者

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

开发者 https://www.devze.com 2022-12-11 22:48 出处:网络
jQuery code: $(document).ready(function() { $(\"#post_submit\").click(function(event) { event.preventDefault();

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(),
      tag开发者_如何学JAVAs: $("#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").


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");
0

精彩评论

暂无评论...
验证码 换一张
取 消