0

i have form and one div named "success". when form is submited "success" div has been shown.

i am trying to do that, when form submitted, page slide to "success" div.

my code is.

$.ajax({
    type: "POST",
    url: "mail.php",
    data: dataString,
    success: function () {
        $('.success').show(1000).delay(5000).fadeOut();
        $("#contact-form")[0].reset();
    }
});

4

2 回答 2

0

You can use the Slide Effect here like:

$('.success').show('slide').delay(5000).fadeOut();

Fiddle Demo #1

UPDATE

For scrolling to the success div, you can do this:

$('html, body').animate({
    scrollTop: $('.success').offset().top
}, 'slow');

Fiddle Demo #2

于 2013-10-31T11:54:18.083 回答
0

try this:

$.ajax({
  type: "POST",
  url: "mail.php",
  data: dataString,
  success: function () {
  var success = $('.success'); //caching the element to enhance performance
    success.show();
    var t = setTimeout(function() {
      success.fadeOut(5000);
    },1000);
    $("#contact-form")[0].reset();
  }
});
于 2013-10-31T11:54:25.777 回答