window.$=function(selector){
return new $.fn.init(selector);
}
$.fn = $.prototype = {
init : function(selector){
selector = selector || document;
if (selector.nodeType) {
this[0] = selector;
this.length = 1;
return this;
}
if(typeof selector == "string"){
return $(document.getElementById(selector));
}
},
html : function(value) {
return value == undefined ? (this[0] ? this[0].innerHTML : null) : (this[0] ? this[0].innerHTML = value : this);
},
css : function(s){
for ( var name in s ) {
this[0].style[ name ] = s[ name ];
}
},
hide : function(speed,func){
speed = speed || 10;
this.css({filter:'alpha(opacity=100)',opacity:1});
var self_ = this;
this.alpha({start:10,end:0,speed:speed},function(){
self_.css({display:"none"});
if(func) func();
});
},
show : function(speed,func){
speed = speed || 10;
this.css({display:""});
this.alpha({start:0,end:10,speed:speed},func);
},
alpha : function(op,func){
var self_ = this;
var n = op.start;
var obj = this[0];
var end = op.end;
var step = op.start > op.end ? -1:1;
var alpha = function(){
n += step;
self_.css({'filter':'alpha(opacity=' + n*10 + ')','opacity':n/10});
if( n != end ){
window.setTimeout(alpha,op.speed);
}else{
if(func) func();
}
};
alpha();
},
val : function(value){
return value == undefined ? (this[0] ? this[0].value : null) : (this[0] ? this[0].value = value : this);
},
drag : function(){
var div = this[0];
var mouseD = false;
var mx = 0,my = 0;
var alphaFlg = false;
div.onmousedown = function(e){
var e = e ? e : event;
if(e.button == (document.all ? 1 : 0)){
mouseD = true;
mx = e.x ? e.x : e.pageX;
my = e.y ? e.y : e.pageY;
$(div).css({'left':this.offsetLeft + "px",'top':this.offsetTop + "px"});
if( $.isIE ){
this.setCapture();
}else{
window.captureEvents(Event.MOUSEMOVE);
}
$(div).css({'filter':'alpha(opacity=80)','opacity':0.8});
}
};
div.onmousemove = function(e){
var e = e ? e : event;
if( mouseD == true ){
var emX = e.x ? e.x : e.pageX;
var emY = e.y ? e.y : e.pageY;
var mrx = emX - mx;
var mry = emY - my;
$(div).css({left:parseInt(div.style.left) + mrx + "px",
top:parseInt(div.style.top) + mry + "px"});
mx = emX;
my = emY;
}
};
div.onmouseup = function(){
mouseD = false;
alphaFlg = false;
if( $.isIE ){
div.releaseCapture();
}else{
window.releaseEvents(div.MOUSEMOVE);
}
$(div).css({'filter':'alpha(opacity=100)','opacity':1});
};
}
}
$.fn.init.prototype = $.fn;
$.extend = $.fn.extend = function() {
var target = arguments[0] || {},
i = 1, length = arguments.length, deep = false, options;
if (target.constructor == Boolean) {
deep = target;
target = arguments[1] || {};
i = 2;
}
if (typeof target != "object" && typeof target != "function")
target = {};
if (length == i) {
target = this;
--i;
}
for (;i < length; i++)
if ((options = arguments[i]) != null)
for (var name in options) {
var src = target[name], copy = options[name];
if (target === copy)
continue;
if (deep && copy && typeof copy == "object" && !copy.nodeType)
target[name] = jQuery.extend(deep, src
|| (copy.length != null ? [] : {}), copy);
else if (copy !== undefined)
target[name] = copy;
}
return target;
};
$.extend({
isIE : !-[1,],
isArray : function(v){
return toString.apply(v) === '[object Array]';
},
isFunction : function(fn) {
return fn instanceof Function;
}
});
// AJAX
$.extend({
get : function(url,data,callback){
return $.ajax({
url : url,
data : data,
success : callback,
type : "GET"
});
},
post : function(url,data,callback){
return $.ajax({
url : url,
data :data,
success : callback,
type : "POST"
});
},
ajax : function(s){
var xhr = window.ActiveXObject
? new ActiveXObject("Microsoft.XMLHTTP")
: new XMLHttpRequest();
var type = s.type.toUpperCase();
var time = s.time ? s.time : 10000;
var url = s.url;
var sendBody = this.formatParam(s.data);
var timer = setTimeout(function(){
if ( typeof s.timeout == "function" ) s.timeout();
if ( xhr ) {
xhr.abort();
xhr = null;
}
return true;
},time);
if ( 'GET' == type ) {
url = [url, ( url.indexOf('?') == -1 ? '?' : '&') ,sendBody].join('');
sendBody = null;
}
if ( ! s.cache ) {
url = [url, ( url.indexOf('?') == -1 ? '?' : '&') , "ajaxtimestamp=" , (new Date()).getTime()].join('');
}
xhr.open(type,url,s.async);
if ( "POST" == type ) xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xhr.onreadystatechange = function(){
if( xhr.readyState == 4 ){
if ( xhr.status == 200 ){
if ( timer ) clearTimeout(timer);
var text = xhr.responseText;
if (s.success) s.success(text);
}
}
}
xhr.send( sendBody );
},
formatParam:function(data){
if ( ! data || typeof data != "object" ) return data;
var k,r = [];
for ( k in data ) {
r.push([k,'=',encodeURIComponent(data[k])].join(''));
}
return r.join('&');
}
})
分享到:
相关推荐
仿照jquery封装一个自己的js库(一)
一个简单的Ajax实例——基于Ajax无需刷新技术开发的聊天室程序,实现多用户在网页上聊天,并可以实时更新信息。
仿照jquery造选择器,空间小仿照jquery造选择器,空间小
该代码知识库是由jquery制作仿照ext框架的知识,内容丰富,包含很多知识,如ext的tree,input输入的验证,form表单的设计,统计试图饼状图、柱状图,窗体wind等知识,欢迎学习该知识。该知识库包含源码和数据,可以直接...
仿照着jquery写了自己的框架,供新手参考
NULL 博文链接:https://makeyouown.iteye.com/blog/1163522
采用javascript和jQuery写的仿照window操作界面源码,点击一个图标,将会弹出一个窗体,改窗体可以最小化和还原,可以在浏览器内移动,底部状态栏可以显示所打开的窗体,该源码是我一年前所写,不足之处多包涵,希望...
基于jQuery框架的ui,风格完全仿照extjs,但代码量很少
ajax+json仿照google提示
仿照windows记事本里写的一个小程序,适合刚入门的朋友们学习!
一个用于选择器和AJAX的自制JavaScript帮助器-仿照jQuery 这是一个简单JavaScript库,用于选择DOM元素并发出AJAX请求。 以下是一些可用功能: Ajaxify() -类似于$.ajax() DOM选择器,例如$('a') , $('.container...
仿照UNP写的client代码,内有我自己的注释
这是一款仿照天猫的菜单导航页面,方便大家开发电商平台
jquery相关例子,仿照w3cshool的相关例子进行相关的实验
【Jquery+css】 仿照微信公众号平台菜单编辑器
我自己用VB写的仿照扫雷游戏的源代码,有些地方可能写得不太好。
然后就想办法仿照JQuery zTree写一个性能高的树形目录 经过努力 最终 实现了 树形目录,当然不能和 JQuery zTree 的功能想比 但是最少我认为从性能和实用性上已完全够用了 通过 Ajax 的 JSON 方法 实现 新增 修改 ...
NULL 博文链接:https://malixxx.iteye.com/blog/612262
仿照uploadify写的,www.codesc.net已做过修正,本例的配置参数均与uploadify官网一致,参照官网的api就可以了,直接把文件夹上传到支持php的服务器即可,上传的文件保存在uploads文件夹。目前的功能: 1.支持多...
仿照struts,自己写的代码 不能说完全一样,个人觉得对想了解struts的朋友会有所帮助的