Created
July 3, 2013 13:27
-
-
Save gmilby/5917838 to your computer and use it in GitHub Desktop.
jquery / ajax spinner = david walsh blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select class="ajax"> | |
<option value="">-- Select a Site--</option> | |
<option value="David Walsh Blog">David Walsh Blog</option> | |
<option value="Script & Style">Script & Style</option> | |
<option value="Band Website Template">Band Website Template</option> | |
</select> | |
<br /><br /> | |
<input type="text" id="my-text" class="ajax" /> | |
$(document).ready(function() { | |
//create image | |
$('<img src="move-spinner.gif" id="spinner" />').css('position','absolute').hide().appendTo('body'); | |
//for every field change | |
$('.ajax').change(function() { | |
//get element position | |
var position = $(this).offset(); | |
//position image | |
$('#spinner').css({ top: position.top , left: position.left + $(this).width() + 30 }).fadeIn(); | |
//ajax | |
$.post('<?php echo $_SERVER['REQUEST_URI']; ?>',{ | |
ajax:1, | |
value: $(this).val() | |
},function() { | |
$('#spinner').fadeOut(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment