<html>
<title>Change Image</title>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$(window).load(function(){
var button = $('#change_button');
var spinner = $('#spinner');
button.css('opacity', 1);
spinner.css('top', ($('.profile_pic').height() - spinner.height()) / 2)
spinner.css('left', ($('.profile_pic').width() - spinner.width()) / 2)
$('.profile_pic').hover(function() {
button.css('opacity', .5);
button.fadeIn(200);
},
function() {
button.fadeOut(200);
});
new AjaxUpload(button,{
action: 'upload.php',
name: 'myfile',
onSubmit : function(file, ext){
spinner.css('display', 'block');
// you can disable upload button
this.disable();
},
onComplete: function(file, response){
button.stop(false,true).fadeOut(200);
spinner.css('display', 'none');
$('#profile_img').attr('src', response);
// enable upload button
this.enable();
}
});
});
</script>
<style type="text/css">
div.profile_pic{
display:block;
position:relative;
width:150px;
height:150px;
}
div.change_button{
position:absolute;
bottom:0px;
left:0px;
display:none;
background-color:black;
font-family: 'tahoma';
font-size:12px;
text-decoration:none;
color:white;
width:150px;
height:150px;
}
div.change_button_text{
padding:10px;
position:absolute;
bottom:0px;
display:block;
}
#spinner{
position:absolute;
}
</style>
</head>
<body>
<div class='profile_pic'>
<img src='http://vasilvasilev.eu/test/noimagebig.jpg' id="profile_img" />
<div class='change_button' id='change_button'>
<div class='change_button_text'>Change my photo</div>
</div>
</div>
<div id="spinner" style="display:none">
<img src="http://vasilvasilev.eu/test/spinner_large.gif" border="0">
</div>
</body>
</html>