Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Fade In and Out With Page Load
    primarykey
    data
    text
    <p>I wonder whether someone may be able to help me please.</p> <p>I know that to some this will be a very basic question, and my apologies, but I've only just started to use jQuery so please bear with me.</p> <p>From working through a tutorial <a href="http://net.tutsplus.com/tutorials/javascript-ajax/building-a-sleek-ajax-signup-form/" rel="nofollow">here</a> I'm using the code below to be triggered on a <code>Submit</code> button.</p> <pre><code>$(document).ready(function(){ $(this).scrollTop(0); $('#addlocation').submit(function(){ //check the form is not currently submitting if($(this).data('formstatus') !== 'submitting'){ //setup variables var form = $(this), formData = form.serialize(), formUrl = form.attr('action'), formMethod = form.attr('method'), responseMsg = $('#saverecordresponse'); //add status data to form form.data('formstatus','submitting'); //show response message - waiting responseMsg.hide() .addClass('response-waiting') .text('Please Wait...') .fadeIn(200); //send data to server for validation $.ajax({ url: formUrl, type: formMethod, data: formData, success:function(data){ //setup variables var responseData = jQuery.parseJSON(data), klass = ''; //response conditional switch(responseData.status){ case 'error': klass = 'response-error'; break; case 'success': klass = 'response-success'; break; } //show reponse message responseMsg.fadeOut(200,function(){ $(this).removeClass('response-waiting') .addClass(klass) .text(responseData.message) .fadeIn(200,function(){ //set timeout to hide response message setTimeout(function(){ responseMsg.fadeOut(250,function(){ $(this).removeClass(klass); form.data('formstatus','idle'); }); },1000) setTimeout(function() { $('body').fadeOut();}, 2000); }); }); } }); } //prevent form from submitting return false; }); }); &lt;/script&gt; </code></pre> <p>The code works, but I'm having a little difficulty at the end of my script, here to be more precise:</p> <pre><code>setTimeout(function() { $('body').fadeOut();}, 2000); </code></pre> <p>This correctly fades the page out after 2 seconds, but I'd now like to fade my page back in after a short delay.</p> <p>I've read a number of posts on this site and tried to incorporate the following:</p> <pre><code>$(this).fadeOut().next().delay(500).fadeIn(); </code></pre> <p>But somewhere along the lines I've done something wrong because the page now fails to fade out or in, but I have to be honest and say I'm not quite sure what I've done wrong.</p> <p>I just wondered whether someone could perhaps take a look at this please and let me know how I can incorporate my existing code and then add a time delay before fading back in.</p> <p>Many thanks and kind regards</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload