一切福田,不離方寸,從心而覓,感無不通。

JavaScript Math 对象的参考手册

Math 对象 Math 对象用于执行数学任务。 使用 Math 的属性和方法的语法:

注释:Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(),像 Math.sin() 这样的函数只是函数,不是某个对象的方法。您无需创建它,通过把 Math 作为对象使用就可以调用其所有属性和方法。 Math 对象属性 FF: Firefox, IE: Internet Explorer 属性 描述 FF IE E 返回算术常量 e,即自然对数的底数(约等于2.718)。 1 3 LN2 返回 2 的自然对数(约等于0.693)。 1 3 LN10 返回 10 的自然对数(约等于2.302)。 1 3 LOG2E 返回以 2 为底的 e 的对数(约等于 1.414)。 1 3 LOG10E 返回以 10 为底的 e 的对数(约等于0.434)。 1 3 PI 返回圆周率(约等于3.14159)。 1 3 SQRT1_2 返回返回 2 的平方根的倒数(约等于 0.707)。 1 3 SQRT2 返回 2 的平方根(约等于 1.414)。 1 3 Math 对象方法 FF: Firefox, IE: Internet […]

龙生   16 Dec 2011
View Details

IE与firefox在Javascript上的区别

 以下以 ie 代替 internet explorer,以 mf 代替 mozzila firefox 1. document.form.item 问题(1)现有问题:现有代码中存在许多 document.formname.item("itemname") 这样的语句,不能在 mf 下运行(2)解决方法:改用 document.formname.elements["elementname"](3)其它参见 2 2. 集合类对象问题(1)现有问题:现有代码中许多集合类对象取用时使用 (),ie 能接受,mf 不能。(2)解决方法:改用 [] 作为下标运算。如:document.forms("formname") 改为 document.forms["formname"]。又如:document.getelementsbyname("inputname")(1) 改为 document.getelementsbyname("inputname")[1](3)其它 3. window.event(1)现有问题:使用 window.event 无法在 mf 上运行(2)解决方法:mf 的 event 只能在事件发生的现场使用,此问题暂无法解决。可以这样变通:原代码(可在ie中运行):<input type="button" name="somebutton" value="提交" onclick="javascript:gotosubmit()"/>…<script language="javascript">function gotosubmit() {…alert(window.event); // use window.event…}</script> 新代码(可在ie和mf中运行):<input type="button" name="somebutton" value="提交" onclick="javascript:gotosubmit(event)"/>…<script language="javascript">function gotosubmit(evt) {evt = evt ? evt : (window.event ? window.event : null);…alert(evt); // use evt…}</script>此外,如果新代码中第一行不改,与老代码一样的话(即 gotosubmit 调用没有给参数),则仍然只能在ie中运行,但不会出错。所以,这种方案 tpl 部分仍与老代码兼容。 4. html 对象的 id 作为对象名的问题(1)现有问题在 ie 中,html 对象的 id 可以作为 document 的下属对象变量名直接使用。在 mf 中不能。(2)解决方法用 getelementbyid("idname") […]

龙生   16 Dec 2011
View Details

给firefox添加ie方法和属性

 <!--if(window.Event){// 修正Event的DOM    /*                                IE5        MacIE5        Mozilla        Konqueror2.2        Opera5    event                        yes        yes            yes            yes                    yes    event.returnValue            yes        yes            no            no                    no    event.cancelBubble            yes        yes            no            no                    no    event.srcElement            yes        yes            no            no                    no    event.fromElement            yes        yes            no            no                    no        */    Event.prototype.__defineSetter__("returnValue",function(b){//         if(!b)this.preventDefault();        return b;        });    Event.prototype.__defineSetter__("cancelBubble",function(b){// 设置或者检索当前事件句柄的层次冒泡        if(b)this.stopPropagation();        return b;        });    Event.prototype.__defineGetter__("srcElement",function(){        var node=this.target;        while(node.nodeType!=1)node=node.parentNode;        return node;        });    Event.prototype.__defineGetter__("fromElement",function(){// 返回鼠标移出的源节点        var node;        if(this.type=="mouseover")            node=this.relatedTarget;        else if(this.type=="mouseout")            node=this.target;        if(!node)return;        while(node.nodeType!=1)node=node.parentNode;        return node;        });    Event.prototype.__defineGetter__("toElement",function(){// 返回鼠标移入的源节点        var node;        if(this.type=="mouseout")            node=this.relatedTarget;        else if(this.type=="mouseover")            node=this.target;        if(!node)return;        while(node.nodeType!=1)node=node.parentNode;        return node;        });    Event.prototype.__defineGetter__("offsetX",function(){        return this.layerX;        });    Event.prototype.__defineGetter__("offsetY",function(){        return this.layerY;        });    }if(window.Document){// 修正Document的DOM    /*                                IE5        MacIE5        Mozilla        Konqueror2.2        Opera5    document.documentElement    yes        yes            yes            yes                    no    document.activeElement        yes        null        no            no                    no        */    }if(window.Node){// 修正Node的DOM    /*                                IE5        MacIE5        Mozilla        Konqueror2.2        Opera5    Node.contains                yes        yes            no            no                    yes    Node.replaceNode            yes        no            no            no                    no    Node.removeNode                yes        no            no            no                    no    Node.children                yes        yes            no            no                    no    Node.hasChildNodes            yes        yes            yes            yes                    no    Node.childNodes                yes        yes            yes            yes                    no    Node.swapNode                yes        no            no            no                    no    Node.currentStyle            yes        yes            no            no                    no        */    Node.prototype.replaceNode=function(Node){// 替换指定节点        this.parentNode.replaceChild(Node,this);        }    Node.prototype.removeNode=function(removeChildren){// 删除指定节点        if(removeChildren)            return this.parentNode.removeChild(this);        else{            var range=document.createRange();            range.selectNodeContents(this);            return this.parentNode.replaceChild(range.extractContents(),this);            }        }    Node.prototype.swapNode=function(Node){// 交换节点        var nextSibling=this.nextSibling;        var parentNode=this.parentNode;        node.parentNode.replaceChild(this,Node);        parentNode.insertBefore(node,nextSibling);        }    }if(window.HTMLElement){    HTMLElement.prototype.__defineGetter__("all",function(){        var a=this.getElementsByTagName("*");        var node=this;        a.tags=function(sTagName){            return node.getElementsByTagName(sTagName);            }        return a;        });    HTMLElement.prototype.__defineGetter__("parentElement",function(){        if(this.parentNode==this.ownerDocument)return null;        return this.parentNode;        });    HTMLElement.prototype.__defineGetter__("children",function(){        var tmp=[];        var j=0;        var n;        for(var i=0;i<this.childNodes.length;i++){            n=this.childNodes[i];            if(n.nodeType==1){                tmp[j++]=n;                if(n.name){                    if(!tmp[n.name])                        tmp[n.name]=[];                    tmp[n.name][tmp[n.name].length]=n;                    }                if(n.id)                    tmp[n.id]=n;                }            }        return tmp;        });    HTMLElement.prototype.__defineGetter__("currentStyle", function(){        return this.ownerDocument.defaultView.getComputedStyle(this,null);        });    HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){        var r=this.ownerDocument.createRange();        r.setStartBefore(this);        var df=r.createContextualFragment(sHTML);        this.parentNode.replaceChild(df,this);        return sHTML;        });    HTMLElement.prototype.__defineGetter__("outerHTML",function(){        var attr;        var attrs=this.attributes;        var str="<"+this.tagName;        for(var i=0;i<attrs.length;i++){            attr=attrs[i];            if(attr.specified)                str+=" "+attr.name+'="'+attr.value+'"';            }        if(!this.canHaveChildren)            return str+">";        return str+">"+this.innerHTML+"</"+this.tagName+">";        });    HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){        switch(this.tagName.toLowerCase()){            case "area":            case "base":            case "basefont":            case "col":            case "frame":            case "hr":            case "img":            case "br":            case "input":            case "isindex":            case "link":            case "meta":            case "param":                return false;            }        return true;        });     HTMLElement.prototype.__defineSetter__("innerText",function(sText){        var parsedText=document.createTextNode(sText);        this.innerHTML=parsedText;        return parsedText;        });    HTMLElement.prototype.__defineGetter__("innerText",function(){        var r=this.ownerDocument.createRange();        r.selectNodeContents(this);        return r.toString();        });    HTMLElement.prototype.__defineSetter__("outerText",function(sText){        var parsedText=document.createTextNode(sText);        this.outerHTML=parsedText;        return parsedText;        });    HTMLElement.prototype.__defineGetter__("outerText",function(){        var r=this.ownerDocument.createRange();        r.selectNodeContents(this);        return r.toString();        });    HTMLElement.prototype.attachEvent=function(sType,fHandler){        var shortTypeName=sType.replace(/on/,"");        fHandler._ieEmuEventHandler=function(e){            window.event=e;            return fHandler();            }        this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);        }    HTMLElement.prototype.detachEvent=function(sType,fHandler){        var shortTypeName=sType.replace(/on/,"");        if(typeof(fHandler._ieEmuEventHandler)=="function")            this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);        else            this.removeEventListener(shortTypeName,fHandler,true);        }    HTMLElement.prototype.contains=function(Node){// 是否包含某节点        do if(Node==this)return true;        while(Node=Node.parentNode);        return false;        }    HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){        switch(where){            case "beforeBegin":                this.parentNode.insertBefore(parsedNode,this);                break;            case "afterBegin":                this.insertBefore(parsedNode,this.firstChild);                break;            case "beforeEnd":                this.appendChild(parsedNode);                break;            case "afterEnd":                if(this.nextSibling)                    this.parentNode.insertBefore(parsedNode,this.nextSibling);                else                    this.parentNode.appendChild(parsedNode);                break;            }        }    HTMLElement.prototype.insertAdjacentHTML=function(where,htmlStr){        var r=this.ownerDocument.createRange();        r.setStartBefore(this);        var parsedHTML=r.createContextualFragment(htmlStr);        this.insertAdjacentElement(where,parsedHTML);        }    HTMLElement.prototype.insertAdjacentText=function(where,txtStr){        var parsedText=document.createTextNode(txtStr);        this.insertAdjacentElement(where,parsedText);        }    HTMLElement.prototype.attachEvent=function(sType,fHandler){        var shortTypeName=sType.replace(/on/,"");        fHandler._ieEmuEventHandler=function(e){            window.event=e;            return fHandler();            }        this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);        }    HTMLElement.prototype.detachEvent=function(sType,fHandler){        var shortTypeName=sType.replace(/on/,"");        if(typeof(fHandler._ieEmuEventHandler)=="function")            this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);        else            this.removeEventListener(shortTypeName,fHandler,true);        }    }//--></script>?> 

龙生   16 Dec 2011
View Details

firefox下window.event的解决方法

 在FireFox下编写事件处理函数是很麻烦的事. 因为FireFox并没有 window.event . 如果要得到 event 对象,就必须要声明时间处理函数的第一个参数为event. 所以为了兼容IE与FireFox,一般的事件处理方法为:btn.onclick=handle_btn_click;function handle_btn_click(evt){    if(evt==null)evt=window.event;//IE    //处理事件.}对于简单的程序,这不算麻烦. 但对于一些复杂的程序,某写函数根本就不是直接与事件挂钩的.如果要把event传进该参数,那么所有的方法都要把event传来传去..这简直就是噩梦. 下面介绍一个解决这个麻烦事的方法,与原理. JScript中,函数的调用是有一个 func.caller 这个属性的.例如 function A(){    B();}function B(){    alert(B.caller);}如果B被A调用,那么B.caller就是A 另外,函数有一个arguments属性. 这个属性可以遍历函数当前执行的参数:function myalert(){    var arr=[];    for(var i=0;i        arr[i]=myalert.arguments[i];    alert(arr.join("-"));}alert("hello","world",1,2,3)就能显示 hello-world-1-2-3(arguments的个数与调用方有关,而与函数的参数定义没有任何关系) 根据这两个属性,我们可以得到第一个函数的event对象:btn.onclick=handle_click;function handle_click(){    showcontent();}function showcontent(){    var evt=SearchEvent();    if(evt&&evt.shiftKey)//如果是基于事件的调用,并且shift被按下        window.open(global_helpurl);    else        location.href=global_helpurl;}function SearchEvent(){    func=SearchEvent.caller;    while(func!=null)    {        var arg0=func.arguments[0];        if(arg0)        {            if(arg0.constructor==Event) // 如果就是event 对象                return arg0;        }        func=func.caller;    }    return null;}这个例子使用了SearchEvent来搜索event对象. 其中 'Event' 是 FireFox 的 event.constructor .在该例子运行时,SearchEvent.caller就是showcontent,但是showcontent.arguments[0]是空.所以 func=func.caller 时,func变为handle_click .handle_click 被 FireFox 调用, 虽然没有定义参数,但是被调用时,第一个参数就是event,所以handle_click.arguments[0]就是event ! 针对上面的知识,我们可以结合 prototype.__defineGetter__ 来实现 window.event 在 FireFox 下的实现: 下面给出一个简单的代码.. 有兴趣的可以补充 if(window.addEventListener){ FixPrototypeForGecko();}function FixPrototypeForGecko(){ HTMLElement.prototype.__defineGetter__("runtimeStyle",element_prototype_get_runtimeStyle); window.constructor.prototype.__defineGetter__("event",window_prototype_get_event); Event.prototype.__defineGetter__("srcElement",event_prototype_get_srcElement);}function element_prototype_get_runtimeStyle(){ //return style instead… return […]

龙生   16 Dec 2011
View Details

瀑布流布局浅析

  简介 如果你经常网上冲浪,这样参差不齐的多栏布局,是不是很眼熟啊? 类似的布局,似乎一夜之间出现在国内外大大小小的网站上,比如 Pinterest (貌似是最早使用这种布局的网站了),Mark之,蘑菇街,点点网,以及淘宝最新上线的“哇哦” 等等,倒是很流行哈~ 在淘宝即将上线的众多产品中,你还会大量看到这样的形式呢。 这种布局适合于小数据块,每个数据块内容相近且没有侧重。通常,随着页面滚动条向下滚动,这种布局还会不断加载数据块并附加至当前尾部。所以,我们给这样的布局起了一个形象的名字 — 瀑布流式布局。   几种实现方式 随着越来越多设计师爱用这种布局,我们作为前端,要尽可能满足视觉/交互设计师的需求。所以,我们整理了下这种布局的几种实现方式,有三种: 1) 传统多列浮动。即 蘑菇街和哇哦 采用的方式,如下图所示: 各列固定宽度,并且左浮动; 一列中的数据块为一组,列中的每个数据块依次排列即可; 更多数据加载时,需要分别插入到不同的列上; 线上例子。 优点: 布局简单,应该说没啥特别的难点; 不用明确知道数据块高度,当数据块中有图片时,就不需要指定图片高度。 缺点: 列数固定,扩展不易,当浏览器窗口大小变化时,只能固定的x列,如果要添加一列,很难调整数据块的排列; 滚动加载更多数据时,还要指定插入到第几列中,还是不方便。 2) CSS3 定义。W3C 中有讲述关于多列布局的文档,排列出来的样子: 由 chrome/ff 浏览器直接渲染出来,可以指定容器的列个数,列间距,列中间边框,列宽度来实现;

column-count 为列数; column-gap 为每列间隔距离; column-rule 为间隔边线大小; column-width 为每列宽度; 当只设置 column-width 时,浏览器窗口小于一列宽度时,列中内容自动隐藏; 当只设置 column-count 时,平均计算每列宽度,列内内容超出则隐藏; 都设了 column-count 和column-width,浏览器会根据 count 计算宽度和 width 比较,取大的那个值作为每列宽度,然后当窗口缩小时,width 的值为每列最小宽度。这边其实很简单,简易自己尝试下,详细可参考 https://developer.mozilla.org/en/CSS3_Columns 中的说明。 线上例子。 优点: 直接 CSS 定义,最方便了; 扩展方便,直接往容器里添加内容即可。 缺点: 只有高级浏览器中才能使用; 还有一个缺点,他的数据块排列是从上到下排列到一定高度后,再把剩余元素依次添加到下一列,这个本质上就不一样了; 鉴于这两个主要缺点,注定了该方法只能局限于高端浏览器,而且,更适合于文字多栏排列。 3) 绝对定位。即 Pinterest ,Mark之,KISSY 采用的方式: 可谓是最优的一种方案,方便添加数据内容,窗口变化,列数/数据块都会自动调整; 线上例子。 缺点: 需要实现知道数据块高度,如果其中包含图片,需要知道图片高度; JS 动态计算数据块位置,当窗口缩放频繁,可能会狂耗性能。 KISSY.Waterfall 实现思路 KISSY 的 Waterfall 组件主要包含两个部分,一个是对现有数据块进行排列计算各自所在的位置; 二是下拉滚动时,触发加载数据操作,并把数据添加到目标容器中。 […]

龙生   16 Dec 2011
View Details

window.event对象详细介绍

 1、event代表事件的状态,例如触发event对象的元素、鼠标的位置及状态、按下的键等等。event对象只在事件发生的过程中才有效。event的某些属性只对特定的事件有意义。比如,fromElement 和 toElement 属性只对 onmouseover 和 onmouseout 事件有意义。  2、属性: altKey, button, cancelBubble, clientX, clientY, ctrlKey, fromElement, keyCode, offsetX, offsetY, propertyName, returnValue, screenX, screenY, shiftKey, srcElement, srcFilter, toElement, type, x, y   3、属性详细说明: 属性名 描述 值 说明 altKey 检查alt键的状态 当alt键按下时,值为True否则为False 只读 shiftKey 检查shift键的状态 当shift键按下时,值为True否则为False 只读 ctrlKey 检查ctrl键的状态 当ctrl键按下时,值为True否则为False 只读 例:(点击按钮时显示那几个特殊键按下的状态) <input type="button" value="点击" onClick="showState()"/> <script> function show(){  alert("altKey:"+window.event.altKey   +"\nshiftKey:"+window.event.shiftKey   +"\nctrlKey:"+window.event.ctrlKey); }</script>  keyCode  检测键盘事件相对应的内码    可读写,可以是任何一个Unicode键盘内码。如果没有引发键盘事件,则该值为0 例:(按回车键让下一组件得到焦点,相当按Tab键) <input type="text" onKeyDown="nextBlur()"/> <input type="text"/> <script> function nextBlur(){  if(window.event.keyCode==13)//回车键的 code   window.event.keyCode=9;//Tab键的code } </script>  srcElement  返回触发事件的元素  Object  只读 例:(点击按钮时显示按钮的name值) <input type="button" value="闽" name="福建" onClick="show()"/> […]

龙生   16 Dec 2011
View Details

安卓2.3可系统文件清单

 打开/system/app下 为防止误删除请先备份1 AccountSyncManager. apk                        账号管理程序(设置里面的账户与同步,删除后进不去)        2 AdobeReader. apk                               PDF阅读器(可删)3 Android_Finance_5_0_for_API_1_6_update. apk    CSL旗下的Invest Pro财经资讯程序(可删)4 AndroidMusicHolic. apk                         CSL的One2Free的流动娱乐服务Musicholic,音乐库(可删)5 ApplicationsProvider. apk                      应用程序支持服务(删除后不能连接电脑同步电话号码)6 AppSharing. apk                                应用程序分享(可删,但进程序列表,按菜单键无分享选项)7 BlackBoard. apk                                内置的黑板皮肤(自带皮肤,可删)8 Bluetooth. apk                             […]

龙生   16 Dec 2011
View Details