JQuery - Practice 1
Monday, May 14, 2012
// FORM SUBMIT HANDLER
$(document).ready(function() {
$('#formId').submit(function() {
if ($('#formId input[type=checkbox]:checked').length) {
return confirm("Устгах уу?");
} else {
alert('Ядаж нэг утга сонгоно уу!');
return false;
}
});
});
// All Checkbox - Checked, Unchecked
function toggleChecked(status) {
$(".checkbox").each( function() {
$(this).attr("checked",status);
})
}
// Scroll - Anchor + Effect
function goToByScroll(id){
$('html,body').animate({
scrollTop: $("#"+id).offset().top
},'slow');
}
// Calling AJAX
$.ajax({
url: "/module/action",
data: "name=name&descr=descr",
type: "POST",
beforeSend: function() {
$('#loader').show();
},
complete: function(){
$('#loader').hide();
}
})
.done(function(data) {
// do something ...
});
// TimeLine
var requestSending = false;
var isDone = false;
$(document).ready(function() {
showTimeLine();
});
$(window).scroll(function() {
if($(window).scrollTop() == $(document).height() - $(window).height()){
showTimeLine();
}
});
function showTimeLine() {
if (!requestSending && !isDone) {
$.ajax({
url: "/news/more",
data: "created=" + get_last_created(),
type: "POST",
beforeSend: function () {
requestSending = true;
},
success: function(data) {
requestSending = false;
// do something ...
}
else
{
// do something
isDone = true;
}
},
error: function(err){
requestSending = false;
}
});
}
}
// Object Each Click
$(document).ready(function() {
$('.timeLinePublish').live("click",function(){
alert($(this).attr("id"));
});
});
<img class="timeLinePublish" id="1" src="publish.png"/>
0 comments:
Post a Comment