VQuery高级特性
css方法
同时设置多个--for in
链式操作
链式操作
函数,链式操作
css 方法链式操作
json的使用
阻止冒泡,默认事件
VQuery插件
插件机制
可以扩展库的功能
extend
为VQuery添加方法
原型
实例
animate---动画
else { iCur=parseInt(getStyle(obj, attr)); } //2.算速度 var iSpeed=(json[attr]-iCur)/8; iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed); //3.检测停止 if(iCur!=json[attr]) { bStop=false; } if(attr=='opacity') { obj.style.filter='alpha(opacity:'+(iCur+iSpeed)+')'; obj.style.opacity=(iCur+iSpeed)/100; } else { obj.style[attr]=iCur+iSpeed+'px'; } } if(bStop) { clearInterval(obj.timer); if(fn) { fn(); } } }, 30) } });
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> #div1 {100px; height:100px; background:red; filter:alpha(opacity: 30); opacity:0.3;} </style> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script src="jquery-1.7.1.js"></script> <script> $(function (){ $('#div1').hover(function (){ $(this).animate({ '200px', height: '200px', opacity: 1}); }, function (){ $(this).animate({ '100px', height: '100px', opacity: 0.3}); }); }); </script> </head> <body>
drag---拖拽
$().extend('drag', function (){
var i=0;
for(i=0;i<this.elements.length;i++)
{
drag(this.elements[i]);
}
function drag(oDiv)
{
oDiv.onmousedown=function (ev)
{
var oEvent=ev||event;
var disX=oEvent.clientX-oDiv.offsetLeft;
var disY=oEvent.clientY-oDiv.offsetTop;
document.onmousemove=function (ev)
{
var oEvent=ev||event;
oDiv.style.left=oEvent.clientX-disX+'px';
oDiv.style.top=oEvent.clientY-disY+'px';
};
document.onmouseup=function ()
{
document.onmousemove=null;
document.onmouseup=null;
};
};
}
});
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> div {100px; height:100px; background:red; position:absolute;} </style> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script src="VQuery.js"></script> <script src="VQuery_drag.js"></script> <script> $(function (){ $('div').drag(); }); </script> </head> <body>