jquery基本2

(function($){

$(function(){

$.msg.init();

$('.box>.open,.box>.close').click(function(){
if(this.className == 'open'){
$(this).nextAll().stop().slideUp(100, function(){
$(this).prev().attr('class','close')
});
}else{
$(this).attr('class','open').nextAll().stop().slideDown(100);
}
});

$('.selectable>ul').on('click', 'li', function(){
var $ul = $(this).parent();
$(this).toggleClass('select');
$('#count').text('[' + $('.select', $ul).length + '/' + $('li', $ul).length + ']');
});

$('#count').prev().click(function(){
var $ul = $(this).parent().parent().next();
var length = $('li', $ul).addClass('select').length;
$('#count').text('[' + length + '/' + length + ']');
}).end().next().click(function(){
var $ul = $(this).parent().parent().next();
var length = $('li', $ul).removeClass('select').length;
$('#count').text('[0/' + length + ']');
});
});

$.extend({
cover: {
init: function(){
$('<div id="cover"/>').appendTo('body').click(function(){
if($('#msg').is('.message')){
$.msg.hide();
}else{
$.msg.sway();
}
});
$(window).on('resize.cover',function(){
$('#cover').width(Math.max($(window).width(),$(document).width()));
});
},
show: function(){
$('#cover').stop(true,true).css({
width: Math.max($(window).width(),$(document).width()),
height: Math.max($(window).height(),$(document).height()),
display: 'block'
}).fadeTo(100,0.6);
},
hide: function(){
$('#cover').stop().fadeTo(100,0.1,function(){
$(this).removeAttr('style');
});
}
},
msg: {
init: function(){
$.cover.init();
$('<div id="msg"/>').appendTo('body');
$(window).on('resize.msg',function(){
$('#msg').center();
});
},
show: function(msg, callback){
$.cover.show();
$('#msg').attr('class', msg ? 'message':'loading').html(msg || '信息加载中,请稍候……').center().show().data('callback', callback);
},
sway: function(){
$('#msg').animate({left:'-=20'},40).animate({left:'+=40'},80).animate({left:'-=30'},60).animate({left:'+=20'},40).animate({left:'-=15'},30).animate({left:'+=5'},10);
},
open: function(url){
$.cover.show();
$('<iframe src="' + url + '" frameborder="0"></iframe>').hide().load(function(){
var width = this.contentDocument.body.offsetWidth;
var height = this.contentDocument.body.offsetHeight;
$(this).css({width:width, height:height}).appendTo($('#msg').attr('class', 'frame').empty()).show().parent().center().show();
}).appendTo('body');
},
hide: function(){
var callback = $('#msg').hide().data('callback');
$.cover.hide();
if(callback){
$('#msg').removeData('callback');
callback();
}
}
},
selected: function(i) {
var yes = '', no='';
$('.selectable>ul>li').each(function(){
if($(this).is('.select')){
yes += $(this).data('id') + ',';
}else{
no += $(this).data('id') + ',';
}
});
if(yes == no){
$.msg.show('没有可操作对象!');
return null;
}else{
if(i == 0){
return {'yes':yes + no, 'no':''};
}else if(i == 1){
return {'yes':yes, 'no':no};
}else{
return {'yes':'', 'no':yes + no};
}
}
},
load: function(url, data, callback, err){
if(!err){
$.msg.show();
}
$.ajax({
url: url,
data: data,
success: function(obj){
if(obj.status == 1){
$.msg.show('没有登陆或者权限不够,请<a href="../login.jsp" target="_top">重新登陆</a>!');
}else{
$.msg.hide();
callback(obj);
}
},
error: function(){
$.msg.show('服务器响应失败,请重试!');
if(err){
err();
}
}
});
}
});

/* 居中显示 */
$.fn.center = function(){
return this.each(function(){
$(this).css({
left: ($(window).width() - $(this).outerWidth())/2,
top: ($(window).height() - $(this).outerHeight())/2 + Math.max($('html').scrollTop(),$('body').scrollTop())
});
});
};

/* 页码处理 */
$.fn.page = function(current, amount, edge){
edge = edge || 5;
return this.each(function(){
var $page = $(this).empty();
if(current > (edge+3)){
$page.append('<b>1</b>');
$page.append('<span>…</span>');
for(var i=(current-edge); i<current; i++){
$page.append('<b>' + i + '</b>');
}
}else{
for(var i=1; i<current; i++){
$page.append('<b>' + i + '</b>');
}
}
$page.append('<span>' + current + '</span>');
if((amount-current) > (edge+2)){
for(var i=(current+1); i<=(current+edge); i++){
$page.append('<b>' + i + '</b>');
}
$page.append('<span>…</span>');
$page.append('<b>' + amount + '</b>');
}else{
for(var i=(current+1); i<=(amount); i++){
$page.append('<b>' + i + '</b>');
}
}
});
};

})(jQuery);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值