JavaScript相关

function getStyle(obj,name){
            if(obj.currentStyle){
                return obj.currentStyle[name];
            }else{
                return getComputedStyle(obj,false)[name];
            }
        }
 
function startMove(obj,json,fnEnd){
        clearInterval(obj.timer);
        obj.timer=setInterval(function(){
            var bStop = true;
            for(var attr in json)
            {
                var cur=0;
                if(attr=="opacity"){
                    cur=Math.round(parseFloat(getStyle(obj,attr))*100);
                }else{
                    cur=parseInt(getStyle(obj,attr));
                }
                var speed=(json[attr]-cur)/6;//(iTarget-cur)/6;
                speed=speed>0?Math.ceil(speed):Math.floor(speed);
                if(cur!=json[attr]){
                    bStop=false;
                }
                if(attr=="opacity"){
                    obj.style.filter="alpha(opcity:"+(cur+speed)+")";
                    obj.style.opacity=(cur+speed)/100;
                }else{
                    obj.style[attr]=cur+speed+"px";
                }
            }
            if(bStop){
                clearInterval(obj.timer);
                if(fnEnd){
                    fnEnd();
                }
            }
        },30);
}

 "完美运动框架"

<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
        #div1{
             200px;
            height: 200px;
            background: red;
            position: absolute;
        }
    </style>
    <script type="text/javascript">
        window.onload=function(){
            var oDiv = document.getElementById("div1");
            var disX=0;
            var disY=0;

            oDiv.onmousedown=function(ev){
                var oEvent=ev||event;

                disX=oEvent.clientX-oDiv.offsetLeft;
                disY=oEvent.clientY-oDiv.offsetTop;

                document.onmousemove=function(ev){
                    var oEvent = ev||event;
                    var l=oEvent.clientX-disX;
                    var t=oEvent.clientY-disY;
                    if(l<0){
                        l=0;
                    }
                    else if(l>document.documentElement.clientWidth-oDiv.offsetWidth){
                        l=document.documentElement.clientWidth-oDiv.offsetWidth;
                    }
                    if(t<0){
                        t=0;
                    }else if(t>document.documentElement.clientHeight-oDiv.offsetHeight){
                        t=document.documentElement.clientHeight-oDiv.offsetHeight;
                    }
                    oDiv.style.left=l+"px";
                    oDiv.style.top=t+"px";
                }

                document.onmouseup=function(){
                    document.onmousemove=null;
                    document.onmouseup=null;
                }
                return false;
            }
        }
    </script>
</head>
<body>
    <div id="div1"></div>
</body>
</html>

 js拖动

function ajax(url,fnSucc,fnFaild)
{
    var oAjax=null;
    if(window.XMLHttpRequest)
    {
        oAjax = new XMLHttpRequest();
    }
    else
    {
        oAjax = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //连接服务器
    oAjax.open("GET",url,true);
    //发送请求
    oAjax.send();
    //接收数据
    oAjax.onreadystatechange=function()
    {
        if(oAjax.readyState==4)
        {    //4读取完成
            if(oAjax.status==200)
            {//成功
                fnSucc(oAjax.responseText);
            }
            else
            {
                if(fnFaild)
                {
                    fnFaild(oAjax.status);
                }
            }
        }
    }
}

Ajax相关

<script type="text/javascript">
        function setCookie(name,value,iDay){
            var oDate = new Date();
            oDate.setDate(oDate.getDate()+iDay);
            document.cookie=name+'='+value+';expires=date';
        }
        function getCookie(name){
            var arr = document.cookie.split(";");
            for(var i=0;i<arr.length;i++){
                var arr2=arr[i].split("=");
                if(arr2[0]==name){
                    return arr2[1];
                }
            }
            return '';
        }
        function removeCookie(name){
            setCookie(name,1,-1);
        }
    </script>

Cookie相关

原文地址:https://www.cnblogs.com/Yellow0-0River/p/5301060.html