澳门新萄京:javascript兑现十六进制颜色值,200八
分类:澳门新萄京最大平台

JavaScript实现16进制颜色值转RGB的方法,javascriptrgb

本文实例讲述了JavaScript实现16进制颜色值转RGB的方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";
<html xmlns=";
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>16进制颜色值转RGB</title>
        <style>
        *{margin:0;padding:0;font-family:'Microsoft yahei'}
        .replace{width:400px;height:210px;margin:0 auto;padding-top:40px;}
        .title{text-align:center;display:block}
          form{width:200px;margin:30px auto;}
          input{outline:none;}
          input[type="button"]{cursor:pointer;}
        </style>
        <script>
        function hexToR(h) {
            return parseInt((cutHex(h)).substring(0, 2), 16)
        }
        function hexToG(h) {
            return parseInt((cutHex(h)).substring(2, 4), 16)
        }
        function hexToB(h) {
            return parseInt((cutHex(h)).substring(4, 6), 16)
        }
        function cutHex(h) {
            return h.charAt(0) == "#" ? h.substring(1, 7) : h
        }
        function setBgColorById(id, sColor) {
            var elems;
            if (document.getElementById) {
                if (elems = document.getElementById(id)) {
                    if (elems.style) elems.style.backgroundColor = sColor;
                }
            }
         }
        </script>
        </head>
        <body>
            <div class="replace">
                <span class="title">JavaScript原生16进制颜色值转RGB值</span>
                 <form name="rgb">
                     <input value="ffffff" maxlength="7" size="16" name="hex" />
               <input onclick="setBgColorById('colorSample',this.form.hex.value);
               this.form.r.value=hexToR(this.form.hex.value);
               this.form.g.value=hexToG(this.form.hex.value);
               this.form.b.value=hexToB(this.form.hex.value);" value="转换" type="button" name="btn"/>
               <br /><br />
                   R:<input style="width:30px" size="3" name="r" />
                G:<input style="width:30px" size="3" name="g" />
                B:<input style="width:30px" size="3" name="b" />
                 </form>               
            </div>
</body>
</html>

运行效果如下图所示:

澳门新萄京 1

希望本文所述对大家的javascript程序设计有所帮助。

本文实例讲述了JavaScript实现16进制颜色值转RGB的方法。分享给大家供大家参考。具体实现...

本文实例讲述了JavaScript实现16进制颜色值转RGB的方法。分享给大家供大家参考。具体实现方法如下:

 

1.文本框焦点问题  
onBlur:当失去输入焦点后产生该事件  
onFocus:当输入获得焦点后,产生该文件  
Onchange:当文字值改变时,产生该事件  
Onselect:当文字加亮后,产生该文件  
  
<input type="text" value="mm" onfocus="if(value=='mm) {value=''}" onblur="if  
(value=='') {value='mm'}">点击时文字消失,失去焦点时文字再出现  
  
  
2.网页按钮的特殊颜色  
<input type=button name="Submit1" value="郭强" size=10 class="s02"  
  
style="  
  
3.鼠标移入移出时颜色变化  
<input type="submit" value="找吧" name="B1" onMouseOut=this.style.color="blue"  
  
onMouseOver=this.style.color="red"  class="button">  
  
4.平面按钮  
<input type=submit value=订阅 style="border:1px solid :#666666; height:17px; width:25pt; font-size:9pt;  
  
color:#666666" name="submit">  
  
5.按钮颜色变化  
<input type=text name="nick"  style="border:1px solid #666666;  font-size:9pt;  height:17px;  
  
color:#ff6600" size="15" maxlength="16">  
  
6.平面输入框  
<input type="text" name="T1" size="20" style="border-style: solid; border-width: 1">  
  
7.使窗口变成指定的大小  
<script>  
window.resizeTo(300,283);  
</script>  
  
8.使文字上下滚动  
<marquee direction=up scrollamount=1 scrolldelay=100 onmouseover='this.stop()' onmouseout='this.start()'  
  
height=60>  
<!-- head_scrolltext -->  
<tr>  
<td>  
共和国  
</table>        <!-- end head_scrolltext -->  
</marquee>  
  
9.状态栏显示该页状态  
<base onmouseover="window.status='网站建设 ' ;return true">  
  
10.可以点击文字实现radio选项的选定  
<br>  
    <input type="radio" name="regtype" value="A03" id="A03">  
<label for="A03"> 情侣 : 一次注册两个帐户</label> <br>  
  
11.可以在文字域的font写onclick事件  
  
12.打印</a>打印网页  
<a href='javascript:window.print ()'>  
  
13.线型输入框  
<input type="text" name="key"  size="12" value="关键字" onFocus=this.select() onMouseOver=this.focus()  
  
class="line">  
  
14.显示文档最后修改日期  
<script language=javascript>  
function hi(str)  
{  
document.write(document.lastModified)  
  
alert("hi" str "!")  
}  
</script>  
  
15.可以在鼠标移到文字上时就触发事件  
<html>  
<head>  
<script language="LiveScript">  
<!-- Hiding  
     function hello() {  
       alert("哈罗!");  
     }  
</script>  
</head>  
<body>  
[url=" onMouseOver=]link[/url]  
</body>  
</html>  
  
16.可以根据网页上的选项来确定页面颜色  
<HTML>  
<HEAD>  
<TITLE>background.html</TITLE>  
</HEAD>  
<SCRIPT>  
<!--  
  
function bgChange(selObj) {  
newColor = selObj.options[selObj.selectedIndex].text;  
document.bgColor = newColor;  
selObj.selectedIndex = -1;  
}  
  
//-->  
</SCRIPT>  
<BODY STYLE="font-family:Arial">  
<B>Changing Background Colors</B>  
<BR>  
<FORM>  
  <SELECT SIZE="8" onChange="bgChange(this);">  
  <OPTION>Red  
  <OPTION>Orange  
  <OPTION>Yellow  
  <OPTION>Green  
  <OPTION>Blue  
  <OPTION>Indigo  
  <OPTION>Violet  
  <OPTION>White  
<OPTION>pink  
  </SELECT>  
</FORM>  
</BODY>  
</HTML>  
  
17.将按钮的特征改变  
<style type="text/css">  
<!--  
.style1 { font-size: 12px; background: #CCCCFF; border-width: thin thin thin thin; border-color: #CCCCFF  
  
#CCCCCC #CCCCCC #CCCCFF}  
.style2 { font-size: 12px; font-weight: bold; background: #CCFFCC; border-width: thin medium medium thin;  
  
border-color: #CCFF99 #999999 #999999 #CCFF99}  
-->  
</style>  
  本例按钮的代码如下:  
<input type="submit" name="Submit" value="提 交" onmouseover="this.className='style2'"  
  
onmouseout="this.className='style1'" class="style1">  
  
18.改变按钮的图片.  
<style type="text/css">  
<!--  
.style3 { font-size: 12px; background: url(image/buttonbg1.gif); border: 0px; width: 60px; height: 22px}  
.style4 { font-size: 12px; font-weight: bold; background: url(image/buttonbg2.gif); border: 0px 0; width:  
  
60px; height: 22px}  
-->  
</style>  
  本例的按钮代码如下:  
<input type="submit" name="Submit2" value="提 交" onmouseover="this.className='style4'"  
  
onmouseout="this.className='style3'" class="style3">  
  
19.打印页面  

在日常开发中,经常会用到不同格式的颜色域值之间的相互转换,以下给出一种解决方法。

复制代码 代码如下:

JS动画,实质是对DOM样式的改变。只要把主流浏览器DOM元素的属性方法搞清楚,做JS动画并不算难。网上也有很多封装好的JS动画库,但大多因为功能过于完善,而至于代码量大动辄过千行,不宜在小项目中使用。这里自己封装了一个很轻量的动画库,主要功能都已实现。难免有疏漏之处,还请大家多多指教。

<a class="content" href="javascript:doPrint();">打印本稿</a>

复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";
<html xmlns=";
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>16进制颜色值转RGB</title>
        <style>
        *{margin:0;padding:0;font-family:'Microsoft yahei'}
        .replace{width:400px;height:210px;margin:0 auto;padding-top:40px;}
        .title{text-align:center;display:block}
          form{width:200px;margin:30px auto;}
          input{outline:none;}
          input[type="button"]{cursor:pointer;}
        </style>
        <script>
        function hexToR(h) {
            return parseInt((cutHex(h)).substring(0, 2), 16)
        }
        function hexToG(h) {
            return parseInt((cutHex(h)).substring(2, 4), 16)
        }
        function hexToB(h) {
            return parseInt((cutHex(h)).substring(4, 6), 16)
        }
        function cutHex(h) {
            return h.charAt(0) == "#" ? h.substring(1, 7) : h
        }
        function setBgColorById(id, sColor) {
            var elems;
            if (document.getElementById) {
                if (elems = document.getElementById(id)) {
                    if (elems.style) elems.style.backgroundColor = sColor;
                }
            }
         }
        </script>
        </head>
        <body>
            <div class="replace">
                <span class="title">JavaScript原生16进制颜色值转RGB值</span>
                 <form name="rgb">
                     <input value="ffffff" maxlength="7" size="16" name="hex" />
               <input onclick="setBgColorById('colorSample',this.form.hex.value);
               this.form.r.value=hexToR(this.form.hex.value);
               this.form.g.value=hexToG(this.form.hex.value);
               this.form.b.value=hexToB(this.form.hex.value);" value="转换" type="button" name="btn"/>
               <br /><br />
                   R:<input style="width:30px" size="3" name="r" />
                G:<input style="width:30px" size="3" name="g" />
                B:<input style="width:30px" size="3" name="b" />
                 </form>               
            </div>
</body>
</html>

 

  
  
20.可以直接写html语言  
document.write("");  
  
21.改变下拉框的颜色  
<select name="classid"  
  
onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)" 
  
size="1" style="color:#008080;font-size: 9pt">  
  
22.转至目标URL  
window.location=""  
  
23.传递该object的form  
UpdateSN('guoqiang99267',this.form)  
function UpdateSN(strValue,strForm)  
{  
  strForm.SignInName.value = strValue;  
  return false;  
}  
  
24.文字标签  
<label for="AltName4"><input name="AltName" type="RADIO" tabindex="931"  id="AltName4"  
  
>guoqiang99859</label>  
  
25.layer2为组件的ID,可以控制组件是否可见  
document.all.item('Layer2').style.display = "block";  
document.all.item('Layer2').style.display = "none";//  
  
26.将页面加入favorite中  
<script language=javascript>  
<!--  
function Addme(){  
url = ""; //你自己的主页地址  
title = "Your Site Name"; //你自己的主页名称  
window.external.AddFavorite(url,title);  
-->  
</script>//  
  
27.过10秒自动关闭页面  
< script language="JavaScript" >  
function closeit() {  
setTimeout("self.close()",10000)  
}  
< /script >  
  
28.可以比较字符的大小  
char=post.charAt(i);  
if(!('0'<=char&&char<='9'))  
  
29.将字符转化为数字  
month = parseInt(char)  
  
30.点击value非空的选项时转向指定连接  
<select onchange='if(this.value!="")window.open(this.value)' class="textinput">  
    <option selected>主办单位</option>  
    <option>-----------------</option>  
    <option value=";  
    <option value=";  
</select>  
  
31.改变背景颜色  
<td width=* class="dp" bgColor=#FAFBFC onmouseover="this.bgColor='#FFFFFF';"  
  
onmouseout="this.bgColor='#FAFBFC';">  
  
32.改变文字输入框的背景颜色  
<style>  
.input2 {background-image: url('..inputbg.gif');   font-size: 12px;  
  
#D0DABB;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}  
</style>  
<input name=content type=text size="47" class="input2" maxlength="50">  
  
33.改变水平线的特征  
<hr size="0" noshade color="#C0C0C0">  
  
34.传递参数的方式  
8  
  
35.页内跳转  
1  
2  
3  
4  
5  
6  
7  
<a name="1">dfdf</a>  
<a name="2">dfdf</a>//  
  
36.两个按键一起按下  
if(event.ctrlKey && window.event.keyCode==13)//  
  
37.刷新页面  
javascript:this.location.reload()//  
  
38.将网页的按钮使能  
<SCRIPT LANGUAGE="JavaScript">  
function haha()  
{  
for(var i=0;i<document.form1.elements.length;i )  
{  
  if(document.form1.elements[i].name.indexOf("bb")!=-1)  
   document.form1.elements[i].disabled=!document.form1.elements[i].disabled;  
}  
}  
</SCRIPT>  
<BODY><form name=form1>  
<INPUT TYPE="button" NAME="aa "  value=cindy onclick=haha()>  
<INPUT TYPE="button" NAME="bb " value=guoguo>  
<INPUT TYPE="button" NAME="bb " value=guoguo>  
  
39.文字移动  
<marquee scrollamount=3 onmouseover=this.stop(); onmouseout=this.start();>  
  
40.双击网页自动跑  
<SCRIPT LANGUAGE="JavaScript">  
var currentpos,timer;  
function initialize()  
{  
timer=setInterval("scrollwindow()",1);  
}  
function sc()  
{  
clearInterval(timer);  
}  
function scrollwindow()  
{  
currentpos=document.body.scrollTop;  
window.scroll(0, currentpos);  
if (currentpos != document.body.scrollTop)  
  sc();  
}  
document.onmousedown=sc  
document.ondblclick=initialize  
</SCRIPT>//  
  
41.后退  
<INPUT TYPE="button" onclick=window.history.back() value=back>  
  
42.前进  
<INPUT TYPE="button" onclick=window.history.forward() value=forward>  
  
43.刷新  
<INPUT TYPE="button" onclick=document.location.reload() value=reload>  
  
44.转向指定网页  
document.location="")  
  
45.在网页上显示实时时间  
<SCRIPT LANGUAGE="JavaScript">  
var clock_id;  
window.onload=function()  
{  
clock_id=setInterval("document.form1.txtclock.value=(new Date);",1000)  
}  
</SCRIPT>//  
  
46.可以下载文件  
document.location.href="目标文件"//  
  
47.连接数据库  
import java.sql.*;  
String myDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";  
Class.forName(myDBDriver);  
Connection conn=DriverManager.getConnection("jdbc:odbc:firm","username","password");  
Statement stmt=conn.createStatement();  
ResultSet rs=stmt.executeQuery(sql);  
rs.getString("column1");//  
  
48.可以直接在页面“div”内写下所需内容  
<INPUT TYPE="button" onclick="a1.innerHTML='<font color=red>*</font>'">  

//十六进制颜色值的正则表达式
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
/*RGB颜色转换为16进制*/
String.prototype.colorHex = function(){
    var that = this;
    if(/^(rgb|RGB)/.test(that)){
        var aColor = that.replace(/(?:(|)|rgb|RGB)*/g,"").split(",");
        var strHex = "#";
        for(var i=0; i<aColor.length; i ){
            var hex = Number(aColor).toString(16);
            if(hex === "0"){
                hex = hex;       
            }
            strHex = hex;
        }
        if(strHex.length !== 7){
            strHex = that;       
        }
        return strHex;
    }else if(reg.test(that)){
        var aNum = that.replace(/#/,"").split("");
        if(aNum.length === 6){
            return that;       
        }else if(aNum.length === 3){
澳门新萄京,            var numHex = "#";
            for(var i=0; i<aNum.length; i =1){
                numHex = (aNum aNum);
            }
            return numHex;
        }
    }else{
        return that;       
    }};
 /*16进制颜色转为RGB格式*/
 String.prototype.colorRgb = function(){
    var sColor = this.toLowerCase();
    if(sColor && reg.test(sColor)){
        if(sColor.length === 4){
            var sColorNew = "#";
                for(var i=1; i<4; i =1){
                    sColorNew = sColor.slice(i,i 1).concat(sColor.slice(i,i 1));       
                }
                sColor = sColorNew;
        }
        //处理六位的颜色值
        var sColorChange = [];
        for(var i=1; i<7; i =2){
            sColorChange.push(parseInt("0x" sColor.slice(i,i 2)));       
        }
        return "RGB(" sColorChange.join(",") ")";
    }else{
        return sColor;       
    }};

运行效果如下图所示:

   这里先说明一下功能和用法,以及注意点,随后是一个很简单的可运行示例。

<a class="content" href="javascript:doPrint();">打印本稿</a>

使用颜色转换方法:

澳门新萄京 2

 

20.可以直接写html语言 
document.write(""); 

复制代码 代码如下:

希望本文所述对大家的javascript程序设计有所帮助。

用法及注意事项:

21.改变下拉框的颜色 
<select name="classid" 

ar sRgb = "RGB(23, 245, 56)" , sHex = "#34538b";
var sHexColor = sRgb.colorHex();
var sRgbColor = sHex.colorRgb();

您可能感兴趣的文章:

  • js获取随机颜色值的函数
  • javascript实现十六进制颜色值(HEX)和RGB格式相互转换
  • RGB颜色值转HTML十六进制(HEX)代码的JS函数
  • js实现可得到不同颜色值的颜色选择器实例
  • 用js实现的十进制的颜色值转换成十六进制的代码
  • Javascript实现Web颜色值转换
  • 用javascript获取任意颜色的更亮或更暗颜色值示例代码

       anim(elemId, cssObj, time, animType, funObj)

onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)" 

您可能感兴趣的文章:

  • RGB颜色值转HTML十六进制(HEX)代码的JS函数
  • 用js实现的十进制的颜色值转换成十六进制的代码
  • JavaScript获取图片像素颜色并转换为box-shadow显示
  • js 翻转颜色实现代码
  • Javascript实现Web颜色值转换
  • Javascript实现颜色rgb与16进制转换的方法
  • JS实现随机颜色的3种方法与颜色格式的转化
  • JavaScript实现把rgb颜色转换成16进制颜色的方法
  • js实现九宫格的随机颜色跳转
  • javascript实现rgb颜色转换成16进制格式
  • JS实现颜色的10进制转化成rgba格式的方法

       参数说明:

size="1" style="color:#008080;font-size: 9pt"> 

              elemId (必选)需要施加动画效果的元素id

22.转至目标URL 
window.location="" 

              cssObj (必选)动画结束时的样式,对象类型,键值对形式,

23.传递该object的form 
UpdateSN('guoqiang99267',this.form) 
function UpdateSN(strValue,strForm) 

  strForm.SignInName.value = strValue; 
  return false; 

                     其中键是能直接用在JS中的“驼峰”形式的css属性,而不是原来的css属性。

24.文字标签 
<label for="AltName4"><input name="AltName" type="RADIO" tabindex="931"  id="AltName4" 

                     例如:{ marginLeft: '200px', top: '200px', borderWidth: '8px'}

>guoqiang99859</label> 

              time (必选)动画持续时间(单位ms)

25.layer2为组件的ID,可以控制组件是否可见 
document.all.item('Layer2').style.display = "block"; 
document.all.item('Layer2').style.display = "none";// 

              animType (可选)默认为线性变化,代码里的Tween类型包含可选的其他参数

26.将页面加入favorite中 
<script language=javascript> 
<!-- 
function Addme(){ 
url = ""; //你自己的主页地址 
title = "Your Site Name"; //你自己的主页名称 
window.external.AddFavorite(url,title); 
--> 
</script>// 

              funObj (可选)如果要此选项,需要加入开始和结束时候执行的函数。

27.过10秒自动关闭页面 
< script language="JavaScript" > 
function closeit() { 
setTimeout("self.close()",10000) 

< /script > 

                     形如:{ el为elemId所指向的元素

28.可以比较字符的大小 
char=post.charAt(i); 
if(!('0'<=char&&char<='9')) 

                start: function (el) { el.innerHTML = 'start!'; },

29.将字符转化为数字 
month = parseInt(char) 

                complete: function (el) { el.innerHTML = 'Completed!'; }

30.点击value非空的选项时转向指定连接 
<select onchange='if(this.value!="")window.open(this.value)' class="textinput"> 
    <option selected>主办单位</option> 
    <option>-----------------</option> 
    <option value="; 
    <option value="; 
</select> 

            }

31.改变背景颜色 
<td width=* class="dp" bgColor=#FAFBFC onmouseover="this.bgColor='#FFFFFF';" 

      

onmouseout="this.bgColor='#FAFBFC';"> 

       几点注意事项:

32.改变文字输入框的背景颜色 
<style> 
.input2 {background-image: url('..inputbg.gif');   font-size: 12px;

              1、没有做低版本浏览器兼容,支持IE8 、FF、chrome、safari、opera

#D0DABB;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px} 
</style> 
<input name=content type=text size="47" class="input2" maxlength="50"> 

              2、注意用能直接用在JS中的“驼峰”形式的css属性(本来应把css转“驼峰”形式,

33.改变水平线的特征 
<hr size="0" noshade color="#C0C0C0"> 

                     但是基本所有JS程序员都能直接写出驼峰形式,所以没转)

34.传递参数的方式 

              3、如果需要把动画应用到绝对定位(position:absolute;)元素上,

35.页内跳转 







<a name="1">dfdf</a> 
<a name="2">dfdf</a>// 

                     需要注意在这些元素上设置CSS的方法。

36.两个按键一起按下 
if(event.ctrlKey && window.event.keyCode==13)// 

                     例如:设置top和marginTop,对于绝对定位元素,应该设置top而不是marginTop,

37.刷新页面 
javascript:this.location.reload()// 

                            更不应该将二者混合使用,因为二者的参考点是不一样的,同时设置很容易造成混乱。

38.将网页的按钮使能 
<SCRIPT LANGUAGE="JavaScript"> 
function haha() 

for(var i=0;i<document.form1.elements.length;i ) 

  if(document.form1.elements[i].name.indexOf("bb")!=-1) 
   document.form1.elements[i].disabled=!document.form1.elements[i].disabled; 


</SCRIPT> 
<BODY><form name=form1> 
<INPUT TYPE="button" NAME="aa "  value=cindy onclick=haha()> 
<INPUT TYPE="button" NAME="bb " value=guoguo> 
<INPUT TYPE="button" NAME="bb " value=guoguo> 

                            所以,这里也不支持同时设置二者。

39.文字移动 
<marquee scrollamount=3 onmouseover=this.stop(); onmouseout=this.start();> 

                            其他相似的同理(left和marginLeft、right和marginRight)

40.双击网页自动跑 
<SCRIPT LANGUAGE="JavaScript"> 
var currentpos,timer; 
function initialize() 

timer=setInterval("scrollwindow()",1); 

function sc() 

clearInterval(timer); 

function scrollwindow() 

currentpos=document.body.scrollTop; 
window.scroll(0, currentpos); 
if (currentpos != document.body.scrollTop) 
  sc(); 

document.onmousedown=sc 
document.ondblclick=initialize 
</SCRIPT>// 

                            同时设置top和bottom、left和right也不支持。

41.后退 
<INPUT TYPE="button" onclick=window.history.back() value=back> 

              4、引用了Tween缓动算法,支持线性、渐入渐出等多种变化方式。

42.前进 
<INPUT TYPE="button" onclick=window.history.forward() value=forward> 

              5、“动画队列”功能尚未实现,此版本为初级版本,疏漏之处还请多多指正。

43.刷新 
<INPUT TYPE="button" onclick=document.location.reload() value=reload> 

 

44.转向指定网页 
document.location="") 

 

45.在网页上显示实时时间 
<SCRIPT LANGUAGE="JavaScript"> 
var clock_id; 
window.onload=function() 

clock_id=setInterval("document.form1.txtclock.value=(new Date);",1000) 

</SCRIPT>// 

 

46.可以下载文件 
document.location.href="目标文件"// 

 <!DOCTYPE HTML>

47.连接数据库 
import java.sql.*; 
String myDBDriver="sun.jdbc.odbc.JdbcOdbcDriver"; 
Class.forName(myDBDriver); 
Connection conn=DriverManager.getConnection("jdbc:odbc:firm","username","password"); 
Statement stmt=conn.createStatement(); 
ResultSet rs=stmt.executeQuery(sql); 
rs.getString("column1");// 

<html>

48.可以直接在页面“div”内写下所需内容 
<INPUT TYPE="button" onclick="a1.innerHTML='<font color=red>*</font>'"> 
[align=center" bgcolor="#E0E0E0" onmouseover=this.className='mouseoverbt'; 

<head>

onmouseout=this.className='mouseout';><a href="tm.asp?classid=76]<font 

<title></title>

color="#000000">录音笔</font></a></td> 
<style> 
.mouseoverbt 

background-image: url(); 
background-repeat: no-repeat; 

.mouseout 

 

</style> 

<style type="text/css">

55.同时按下CTRL和Q键 
document.onkeydown=function() 

if(event.ctrlKey&&event.keyCode==81) 
{alert(1)} 
}// 

       #container{ border:1px solid #000; width:500px; height:400px;}

56.以下是一个完整的显示hint的代码,其思想是当鼠标停留是将div中的内容显示在鼠标出,当鼠标移出后在将该div隐 

       #aa{ border:1px solid #000; width:100px; height:40px; background-color:#0f0;

藏掉 
--------------------------------------------------------------------------------------------------------- 

            position:absolute; left:50px; top:50px; }

------------ 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<style> 
#hint{ 
width:198px; 
border:1px solid #000000; 
background:#99ff33; 
position:absolute; 
z-index:9; 
padding:6px; 
line-height:17px; 
text-align:left; 
top: 1520px; 

</style> 
<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
function showme() 

var oSon=window.document.getElementById("hint"); 
if (oSon==null) return; 
with (oSon) 

  innerText=guoguo.value; 
  style.display="block"; 
  style.pixelLeft=window.event.clientX window.document.body.scrollLeft 6; 
  style.pixelTop=window.event.clientY window.document.body.scrollTop 9; 


function hidme() 

var oSon=window.document.getElementById("hint"); 
if (oSon==null) return; 
oSon.style.display="none"; 

//--> 
</SCRIPT> 
<BODY> 
<text id=guoguo value=ga> 
<a href=# onmouseover=showme() onmouseout=hidme() onmousemove=showme() son=hint>dfdfd</a> 

       #bb{ border:1px solid #000; width:500px; height:40px; margin-top:100px;}

  <h5><b><font size="4" color="#FF0000">HTML中的XML数据岛记录编辑与添加    </font></b></h5> 
  </TD></TR></Table> 
  <HR> 
  酒店名称:<input type=text datasrc=#theXMLisland DataFLD=NAME size="76"><BR> 
  地址:<input type=text datasrc=#theXMLisland DataFLD=Address size="76"><BR> 
  主页:<input type=text datasrc=#theXMLisland DataFLD=HomePage size="76"><BR> 
  电子邮件:<input type=text datasrc=#theXMLisland DataFLD=E-Mail size="76"><BR> 
  电话:<input type=text datasrc=#theXMLisland DataFLD=TelePhone size="76"><BR> 
  级别:<input type=text datasrc=#theXMLisland DataFLD=Grade size="76"><HR> 
  <input id="first" TYPE=button value="<< 第一条记录"     onclick="theXMLisland.recordset.moveFirst()"> 
  <input id="prev" TYPE=button value="<上一条记录"   onclick="theXMLisland.recordset.movePrevious()"> 
  <input id="next" TYPE=button value="下一条记录>" onclick="theXMLisland.recordset.moveNext()"> 
  <input id="last" TYPE=button value="最后一条记录>>" onclick="theXMLisland.recordset.moveLast()">  
  <input id="Add" TYPE=button value="添加新记录" onclick="theXMLisland.recordset.addNew()"> 

       #cc{ border:1px solid #000; width:500px; height:40px;}

  <XML ID="theXMLisland"> 
  <HotelList> 
  <Hotel> 
  <Name>四海大酒店</Name> 
  <Address>海魂路1号</Address> 
  <HomePage>www.sihaohotel.com.cn</HomePage> 
  <E-Mail>master@sihaohotel.com.cn</E-Mail> 
  <TelePhone>(0989)8888888</TelePhone> 
  <Grade>五星级</Grade> 
  </Hotel> 
  <Hotel> 
  <Name>五湖宾馆</Name> 
  <Address>东平路99号</Address> 
  <HomePage>www.wuhu.com.cn</HomePage> 
  <E-Mail>web@wuhu.com.cn</E-Mail> 
  <TelePhone>(0979)1111666</TelePhone> 
  <Grade>四星级</Grade> 
  </Hotel> 
  <Hotel> 
  <Name>“大沙漠”宾馆</Name> 
  <Address>留香路168号</Address> 
  <HomePage>www.dashamohotel.com.cn</HomePage> 
  <E-Mail>master@dashamohotel.com.cn</E-Mail> 
  <TelePhone>(0989)87878788</TelePhone> 
  <Grade>五星级</Grade> 
  </Hotel> 
  <Hotel> 
  <Name>“画眉鸟”大酒店</Name> 
  <Address>血海飘香路2号</Address> 
  <HomePage>www.throstlehotel.com.cn</HomePage> 
  <E-Mail>chuliuxiang@throstlehotel.com.cn</E-Mail> 
  <TelePhone>(099)9886666</TelePhone> 
  <Grade>五星级</Grade> 
  </Hotel> 
  </HotelList> 
  </XML> 

</style>

  </body> 
  </HTML> //xml数据岛中添加记录 
199.模式窗口 
父窗口 
var url="aaa.jsp"; 
var 

</head><body>

data=showModalDialog(url,null,"dialogHeight:400px;dialogHeight:600px;center:yes;help:No;status:no;resizab 

<div id="container">

le:Yes;edge:sunken"); 
if(data) 
alert(data.value); 

<input id="Abegin" type="button" value="开始" />

子窗口 
var data=new Object(); 
data.value1="china"; 
window.returnValue=data; 
window.close(); 

<input id="Apause" type="button" value="暂停" />

200.动态设置事件,带参数 
<INPUT TYPE="text" NAME="a1"> 
<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
function hah(para) 

alert(para) 

a1.onclick=function() 

hah('canshu ') 

//a1.attachEvent("onclick",function(){hah('参数')}); 
//--> 
</SCRIPT>// 

<input onclick="location.reload()" type="button" value="刷新网页" />

201.将url转化为16进制形式 
var ret = ''; 

<div id="aa"><br /></div>

for(var i=0; i < str.length; i ) 

  var ch = str.charAt(i); 
  var code = str.charCodeAt(i); 

<div id="bb">dfdfddfsd</div>

  if(code < 128 && ch != '[' && ch != ''' && ch != '=') 
  { 
   ret = ch; 
  } 
  else 
  { 
   ret = "[" code.toString(16) "]"; 
  } 

return ret;// 

<div id="cc">gregreger</div>

202.打开新的窗口并将新打开的窗口设置为活动窗口 
var newWin=window.open("xxxx"); 
newWin.focus();// 

</div>

203.容错脚本 
JS中遇到脚本错误时不做任何操作:window.onerror = doNothing; 
指定错误句柄的语法为:window.onerror = handleError 
function handleError(message, URI, line) 
{// 提示用户,该页可能不能正确回应 
return true; // 这将终止默认信息 
}//在页面出错时进行操作 

<script type="text/javascript">

204.JS中的窗口重定向: 
window.navigate(" 

(function () {

205.防止链接文字折行 
document.body.noWrap=true;// 

    var Tween = {

206.判断字符是否匹配. 
string.match(regExpression)// 

        Linear: function (t, b, c, d) { return c * t / d b; },

207. 
href="javascript:document.Form.Name.value='test';void(0);"//不能用onClick="javacript:document.Form.Name.v 

        Quad: {

alue='test';return false;" 

            easeIn: function (t, b, c, d) {

当使用inline方式添加事件处理脚本事,有一个被包装成匿名函数的过程,也就是说 
onClick="javacript:document.Form.Name.value='test';return false;"被包装成了: 
functoin anonymous() 

    document.Form.Name.value='test';return false; 

做为A的成员函数onclick。 
而href="javascript:document.Form.Name.value='test';void(0);"相当于执行全局语句,这时如果使用return语句会 

                return c * (t /= d) * t b;

报告在函数外使用return语句的错误。 

            },

208.进行页面放大 
<P onmouseover="this.style.zoom='200%'" onmouseout="this.style.zoom='normal'"> 
sdsdsdsdsdsdsdsds 
</p>// 

            easeOut: function (t, b, c, d) {

209.放置在页面的最右边 
<input type="text" value='bu2'  style="float:right">// 

                return -c * (t /= d) * (t - 2) b;

210.通过style来控制隔行显示不同颜色 
<style> 
tr{ 
bgcolor:expression(this.bgColor=((this.rowIndex)%2==0 )? 'white' : 'yellow'); 

</style> 
<table id="oTable" width="100" border="1" style="border-collapse:collapse;"> 
<tr><td> </td></tr> 
<tr><td> </td></tr> 
<tr><td> </td></tr> 
<tr><td> </td></tr> 
<tr><td> </td></tr> 
</table>// 

            },

211.全屏最大化 
newwindow=window.open("","","scrollbars") 
if (document.all) 

newwindow.moveTo(0,0) 
newwindow.resizeTo(screen.width,screen.height) 
}// 

            easeInOut: function (t, b, c, d) {

212.根据名字解析xml中的节点值 
var XMLDoc=new ActiveXObject("MSXML"); 
XMLDoc.url="d:/abc.xml"; 
aRoot=XMLDoc.root; 
a1.innerText=aRoot.children.item("name").text;// 

                if ((t /= d / 2) < 1) return c / 2 * t * t b;

213.在页面上解析xml的值 
 

                return -c / 2 * ((--t) * (t - 2) - 1) b;

fcccdf35.asp 
// 

            }

214.看一个字符串里面有多少个回车符,返回值是一个数组 
var s=value.match(/n/g);if(s)if(s.length==9){alert('10行了');return false;}// 

        },

215.获得asc码 
var s='aa'; 
alert(s.charCodeAt(1))// 

        Cubic: {

216.文字居右对齐 
<input type="text" value="123" style="text-align:right">// 

            easeIn: function (t, b, c, d) {

217.判断一个方法是否存在 
function pageCallback(response){ 
alert(response); 

if(pageCallback) 
alert(1)// 

                return c * (t /= d) * t * t b;

218.判断一个变量是否定义 
if(typeof(a)=="undefined") 

alert() 
}// 

            },

219.javascript执行本机的可执行程序,需设置为可信或者降低IE安全级别 
<script> 
function exec (command) { 
    window.oldOnError = window.onerror; 
    window._command = command; 
    window.onerror = function (err) { 
      if (err.indexOf('utomation') != -1) { 
        alert('命令已经被用户禁止!'); 
        return true; 
      } 
      else return false; 
    }; 
    var wsh = new ActiveXObject('WScript.Shell'); 
    if (wsh) 
      wsh.Run(command); 
    window.onerror = window.oldOnError; 
  } 
</script> 
调用方式 
测试// 

            easeOut: function (t, b, c, d) {

220.弹出新页面,关闭旧页面,不弹出提示框 
var w=screen.availWidth-10; 
   var h=screen.availHeight-10; 
   var swin=window.open("/mc/mc/message_management.jsp", 

                return c * ((t = t / d - 1) * t * t 1) b;

"BGSMbest","scrollbars=yes,status,location=0,menubar=0,toolbar=0,resizable=no,top=0,left=0,height=" h ",w 

            },

idth=" w); 
   window.opener=null; 
   window.close();// 

            easeInOut: function (t, b, c, d) {

221.能输入的下拉框 
<span> 
<input name="Department1" id="Department1" style=" border-right:0;width:130" autocomplete="off"> 
<span style="width:150;overflow:hidden"> 
<select  style="width:150;margin-left:-130" onChange="Department1.value=value"> 
<option value=""></option> 
<option value="asdfasfadf">asdfasfadf</option> 
<option value="546546">546546</option></select> // 

                if ((t /= d / 2) < 1) return c / 2 * t * t * t b;

222.在方法中定义全局变量 
function globalVar (script) { 
        eval(script);//all navigators 
  //window.execScript(script); //for ie only 

globalVar('window.haha = "../system";'); 
alert(haha);//在方法中定义全局变量,其中的haha就是全局变量了 

                return c / 2 * ((t -= 2) * t * t 2) b;

223.显示一个对象的全部的属性和属性的值 
var a=new Object(); 
a.name='a1'; 
a.***='mail' 
for(var p in a) 

alert(p "=" a[p]) 
}// 

            }

224.16进制转换成10进制 
var n = parseInt("2AE",16);//这里将16进制的 2AE 转成 10 进制数,得到 n 的值是 686 

        },

225.复制粘贴 
<BODY> 
<input type="file" name='a1'><input type="button" value='复制粘贴' onclick="haha()"><div id="aa">

        Quart: {

<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
function haha() 

clipboardData.setData("Text",a1.value); 
aa.innerText=clipboardData.getData("Text"); 

//--> 
</SCRIPT> 
</BODY>// 

            easeIn: function (t, b, c, d) {

226.获得对象类型 
switch (object.constructor){ 
   case Date: 
   ... 
   case Number: 
   ... 
   case String: 
   ... 
   case MyObject: 
   ... 
   default: 
   ... 
}// 

                return c * (t /= d) * t * t * t b;

227.图片加载失败时重新加载图片 
<img src="aa.gif" onerror="this.src='aa.gif'">// 

            },

228. 
//font_effect.htc 
<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="glowit()" /> 
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="noglow()" /> 
<SCRIPT LANGUAGE="JScript"> 
//定义一个保存字体颜色的变量 
var color; 
function glowit() 

color=element.style.backgroundColor; 
element.style.backgroundColor='white' 

function noglow() 

  element.style.backgroundColor=color 

</SCRIPT> 

            easeOut: function (t, b, c, d) {

//abc.css 
tr{behavior:url(font_effect.htc);} 

                return -c * ((t = t / d - 1) * t * t * t - 1) b;

229.可以通过css和htc改变表格的颜色,仅IE支持 
//xxx.html 
<link rel="stylesheet" type="text/css" href="abc.css"> 
<TABLE border='1'  id="a1"> 
<TR style=" 
<TD>1</TD> 
<TD>2</TD> 
<TD>3</TD> 
</TR> 
<TR style=" 
<TD>4</TD> 
<TD>5</TD> 
<TD>6</TD> 
</TR> 
</TABLE>// 

            },

230.在页面上画点 
function a(x,y,color) 

document.write("<img border='0' style='position: absolute; left: " (x 20) "; top: 

            easeInOut: function (t, b, c, d) {

" (y 20) ";") 
}// 

                if ((t /= d / 2) < 1) return c / 2 * t * t * t * t b;

231.自动关闭网页 
<script LANGUAGE="javascript"> 
<!-- 
setTimeout('window.close();', 10000); //60秒后关闭 
// --> 
</script> 
本页10秒后自动关闭,请注意刷新页面

                return -c / 2 * ((t -= 2) * t * t * t - 2) b;

            }

        },

        Quint: {

            easeIn: function (t, b, c, d) {

                return c * (t /= d) * t * t * t * t b;

            },

            easeOut: function (t, b, c, d) {

                return c * ((t = t / d - 1) * t * t * t * t 1) b;

            },

            easeInOut: function (t, b, c, d) {

                if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t b;

                return c / 2 * ((t -= 2) * t * t * t * t 2) b;

            }

        },

        Sine: {

            easeIn: function (t, b, c, d) {

                return -c * Math.cos(t / d * (Math.PI / 2)) c b;

            },

            easeOut: function (t, b, c, d) {

                return c * Math.sin(t / d * (Math.PI / 2)) b;

            },

            easeInOut: function (t, b, c, d) {

                return -c / 2 * (Math.cos(Math.PI * t / d) - 1) b;

            }

        },

        Expo: {

            easeIn: function (t, b, c, d) {

                return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) b;

            },

            easeOut: function (t, b, c, d) {

                return (t == d) ? b c : c * (-Math.pow(2, -10 * t / d) 1) b;

            },

            easeInOut: function (t, b, c, d) {

                if (t == 0) return b;

                if (t == d) return b c;

                if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) b;

                return c / 2 * (-Math.pow(2, -10 * --t) 2) b;

            }

        },

        Circ: {

            easeIn: function (t, b, c, d) {

澳门新萄京:javascript兑现十六进制颜色值,200八个js技艺代码。                return -c * (Math.sqrt(1 - (t /= d) * t) - 1) b;

            },

            easeOut: function (t, b, c, d) {

                return c * Math.sqrt(1 - (t = t / d - 1) * t) b;

            },

            easeInOut: function (t, b, c, d) {

                if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) b;

                return c / 2 * (Math.sqrt(1 - (t -= 2) * t) 1) b;

            }

        },

        Elastic: {

            easeIn: function (t, b, c, d, a, p) {

                if (t == 0) return b; if ((t /= d) == 1) return b c; if (!p) p = d * .3;

                if (!a || a < Math.abs(c)) { a = c; var s = p / 4; }

                else var s = p / (2 * Math.PI) * Math.asin(c / a);

                return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) b;

            },

            easeOut: function (t, b, c, d, a, p) {

                if (t == 0) return b; if ((t /= d) == 1) return b c; if (!p) p = d * .3;

                if (!a || a < Math.abs(c)) { a = c; var s = p / 4; }

                else var s = p / (2 * Math.PI) * Math.asin(c / a);

                return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) c b);

            },

            easeInOut: function (t, b, c, d, a, p) {

                if (t == 0) return b; if ((t /= d / 2) == 2) return b c; if (!p) p = d * (.3 * 1.5);

                if (!a || a < Math.abs(c)) { a = c; var s = p / 4; }

                else var s = p / (2 * Math.PI) * Math.asin(c / a);

                if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) b;

                return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 c b;

            }

        },

        Back: {

            easeIn: function (t, b, c, d, s) {

                if (s == undefined) s = 1.70158;

                return c * (t /= d) * t * ((s 1) * t - s) b;

            },

            easeOut: function (t, b, c, d, s) {

                if (s == undefined) s = 1.70158;

                return c * ((t = t / d - 1) * t * ((s 1) * t s)

  • 1) b;

            },

            easeInOut: function (t, b, c, d, s) {

                if (s == undefined) s = 1.70158;

                if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) 1) * t - s)) b;

                return c / 2 * ((t -= 2) * t * (((s *= (1.525)) 1) * t s) 2) b;

            }

        },

        Bounce: {

            easeIn: function (t, b, c, d) {

                return c - Tween.Bounce.easeOut(d - t, 0, c, d) b;

            },

            easeOut: function (t, b, c, d) {

                if ((t /= d) < (1 / 2.75)) {

                    return c * (7.5625 * t * t) b;

                } else if (t < (2 / 2.75)) {

                    return c * (7.5625 * (t -= (1.5 / 2.75)) * t .75) b;

                } else if (t < (2.5 / 2.75)) {

                    return c * (7.5625 * (t -= (2.25 / 2.75)) * t .9375) b;

                } else {

                    return c * (7.5625 * (t -= (2.625 / 2.75)) * t .984375) b;

                }

            },

            easeInOut: function (t, b, c, d) {

                if (t < d / 2) return Tween.Bounce.easeIn(t * 2, 0, c, d) * .5 b;

                else return Tween.Bounce.easeOut(t * 2 - d, 0, c, d) * .5 c * .5 b;

            }

        }

    }

 

 

    var color = {

        sub: function (str, start, len) {

            if (len) return str.substring(start, start len);

            else return str.substring(start);

        },

        hex: function (i) {  // 返回16进制颜色表示

            if (i < 0) return "00";

            else if (i > 255) return "ff";

            else { var str = "0" i.toString(16); return str.substring(str.length - 2); }

        },

        //获取颜色数据   

        GetColors: function (sColor) {

            sColor = sColor.replace("#", "");

            var r, g, b;

            if (sColor.length > 3) {

                r = color.sub(sColor, 0, 2); g = color.sub(sColor, 2, 2); b = color.sub(sColor, 4, 2);

            } else {

                r = color.sub(sColor, 0, 1); g = color.sub(sColor, 1, 1); b = color.sub(sColor, 2, 1);

                r = r; g = g; b = b;

            }

            return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16)];

        }

    }

 

    var fn = {

        getElement: function (id) {

            return typeof id == "string" ? document.getElementById(id) : id;

        },

        objType: function (obj) {

            switch (Object.prototype.toString.call(obj)) {

                case "[object Object]":

                    return "Object";

                case "[object Number]":

                    return "Number";

                case "[object Array]":

                    return "Array";

            }

        },

        getStyle: function (elem, name) { //

            var w3style;

            if (document.defaultView) {

                var style = document.defaultView.getComputedStyle(elem, null);

                name == "borderWidth" ? name = "borderLeftWidth" : name; // 解决标准浏览器解析问题

                w3style = name in style ? style[name] : style.getPropertyValue(name);

                w3style == "auto" ? w3style = "0px" : w3style;

            }

            return elem.style[name] ||

            (elem.currentStyle && (elem.currentStyle[name] == "auto" ? "0px" : elem.currentStyle[name])) || w3style;

        },

        getOriCss: function (elem, cssObj) { // 此处只能获取属性值为数值类型的style属性

            var cssOri = [];

            for (var prop in cssObj) {

                if (!cssObj.hasOwnProperty(prop)) continue;

                //if (prop != "opacity") cssOri.push(parseInt(fn.getStyle(elem, prop)));

                //else cssOri.push(100 * fn.getStyle(elem, prop));

                if (fn.getStyle(elem, prop) == "transparent" || /^#|rgb(/.test(fn.getStyle(elem, prop))) {

                    if (fn.getStyle(elem, prop) == "transparent") {

                        cssOri.push([255, 255, 255]);

                    }

                    if (/^#/.test(fn.getStyle(elem, prop))) {

                        cssOri.push(color.GetColors(fn.getStyle(elem, prop)));

                    }

                    if (/^rgb(/.test(fn.getStyle(elem, prop))) {

                        //cssOri.push([fn.getStyle(elem, prop).replace(/^rgb()/g, "")]);

                        var regexp = /^rgb(([0-9]{0,3}),s([0-9]{0,3}),s([0-9]{0,3}))/g;

                        var re = fn.getStyle(elem, prop).replace(regexp, "$1 $2 $3").split(" ");

                        //cssOri.push(re); // re为字符串数组

                        cssOri.push([parseInt(re[0]), parseInt(re[1]), parseInt(re[2])]);

                    }

                } else if (prop == "opacity") {

                    cssOri.push(100 * fn.getStyle(elem, prop));

                } else {

                    cssOri.push(parseInt(fn.getStyle(elem, prop)));

                }

            }

            return cssOri;

        },

        getEndCss: function (cssobj) {

            var cssEnd = [];

            for (var prop in cssobj) {

                if (!cssobj.hasOwnProperty(prop)) continue;

                //if (prop != "opacity") cssEnd.push(parseInt(cssobj[prop]));

                //else cssEnd.push(100 * cssobj[prop]);

                if (prop == "opacity") {

                    cssEnd.push(100 * cssobj[prop]);

                } else if (/^#/.test(cssobj[prop])) {

                    cssEnd.push(color.GetColors(cssobj[prop]));

                } else {

                    cssEnd.push(parseInt(cssobj[prop]));

                }

            }

            return cssEnd;

        }

    }

 

    function _anim(/*elemId, cssObj, time, animType, funObj*/) {

        this.init.apply(this, arguments[0]);

    }

    _anim.prototype = {

        init: function () {

            this.elem = fn.getElement(arguments[0]);

            this.cssObj = arguments[1];

            this.cssOri = fn.getOriCss(this.elem, arguments[1]);

            this.cssEnd = fn.getEndCss(arguments[1]);

            this.durtime = arguments[2];

            this.animType = "Tween.Linear";

            this.funObj = null;

            this.start = false;

            this.complete = false;

            this.onPause = false;

            this.onRestart = false;

 

            if (arguments.length < 3) {

                throw new Error("至少要传入3个参数");

            } else if (arguments.length == 4) {

                if (fn.objType(arguments[3]) == "Object") {

                    this.funObj = arguments[3];

                    for (var p in this.funObj) {

                        if (p.toString() == "start") this.start = true;

                        if (p.toString() == "complete") this.complete = true;

                    }

                }

                if (typeof (arguments[3]) == "string") {

                    this.animType = arguments[3];

                }

            } else if (arguments.length == 5) {

                this.animType = arguments[3];

                if (fn.objType(arguments[4]) == "Object") {

                    this.funObj = arguments[4];

                    for (var p in this.funObj) {

                        if (p.toString() == "start") this.start = true;

                        if (p.toString() == "complete") this.complete = true;

                    }

                }

            }

            this.startAnim();

        },

        startAnim: function () {

            if (this.start) this.funObj["start"].call(this, this.elem);

            var that = this;

            var t = 0;

            var props = [];

            for (var pro in this.cssObj) {

                if (!this.cssObj.hasOwnProperty(pro)) continue;

                props.push(pro);

            }

            var tt = new Date().getTime();

            clearInterval(this.timer);

            this.timer = setInterval(function () {

                if (that.onPause) {

                    clearInterval(that.timer);

                    return;

                }

                if (t < that.durtime / 10) {

                    t ;

                    for (var i = 0; i < props.length; i ) {

                        var b, c;

                        fn.objType(that.cssOri[i]) != "Array" && (b = that.cssOri[i]); //开始值

                        fn.objType(that.cssEnd[i]) != "Array" && (c = that.cssEnd[i] - that.cssOri[i]); // 变化量

                        var d = that.durtime / 10; // 持续时间

                        if (fn.objType(that.cssOri[i]) == "Array" && fn.objType(that.cssEnd[i]) == "Array") {

                            var b1 = that.cssOri[i][0], b2 = that.cssOri[i][1], b3 = that.cssOri[i][2];

                            var c1 = that.cssEnd[i][0] - that.cssOri[i][0],

                                c2 = that.cssEnd[i][1] - that.cssOri[i][1],

                                c3 = that.cssEnd[i][2] - that.cssOri[i][2];

                            var r = color.hex(Math.ceil((eval(that.animType))(t, b1, c1, d))),

                                g = color.hex(Math.ceil((eval(that.animType))(t, b2, c2, d))),

                                b = color.hex(Math.ceil((eval(that.animType))(t, b3, c3, d)));

                            that.elem.style[props[i]] = "#" r g

  • b;

 

                        } else if (props[i].toString() == "opacity") {

                            that.elem.style[props[i]] = Math.ceil((eval(that.animType))(t, b, c, d)) / 100;

                        } else {

                            that.elem.style[props[i]] = Math.ceil((eval(that.animType))(t, b, c, d)) "px";

                        }

                    }

                } else {

                    for (var i = 0; i < props.length; i ) {

                        if (fn.objType(that.cssOri[i]) == "Array" && fn.objType(that.cssEnd[i]) == "Array") {

                            var c1 = that.cssEnd[i][0],

                                c2 = that.cssEnd[i][1],

                                c3 = that.cssEnd[i][2];

                            var r = color.hex(Math.ceil((eval(that.animType))(t, b1, c1, d))),

                                g = color.hex(Math.ceil((eval(that.animType))(t, b2, c2, d))),

                                b = color.hex(Math.ceil((eval(that.animType))(t, b3, c3, d)));

                            that.elem.style[props[i]] = "#" r g

  • b;

                        } else if (props[i].toString() == "opacity") {

                            that.elem.style[props[i]] = that.cssEnd[i] / 100;

                        } else {

                            that.elem.style[props[i]] = that.cssEnd[i] "px";

                        }

                    }

                    clearInterval(that.timer);

                    if (that.complete) that.funObj["complete"].call(that, that.elem);

                    //alert(new Date().getTime() - tt);

                }

            }, 10); // 一般要给10毫秒异步调用时间,不能是1

        },

        pause: function () {

            this.onPause = true;

        }

    } www.2cto.com

 

    window.anim = function () {

        return new _anim(arguments);

    }

})();

 

</script>

<script type="text/javascript">

           var bbtn = document.getElementById("Abegin"),

            pbtn = document.getElementById("Apause");

           var a;

        bbtn.onclick = function () {

            a = anim("aa", {

                    left: '200px',

                    top: '200px',

                    width: '200px',

                    height: '200px',

                    backgroundColor: '#f00',

                    borderWidth: '8px'

                }, 4000, 'Tween.Bounce.easeInOut', {

                    start: function (el) { el.innerHTML = 'start!'; }, 

                    complete: function (el) { el.innerHTML = 'Completed!'; }

                }

            );

        }

        pbtn.onclick = function () {

            a.pause();

        }

        anim("bb", {

                marginTop:'160px',

澳门新萄京:javascript兑现十六进制颜色值,200八个js技艺代码。                opacity:0.1,

                   width: '200px',

                   height: '200px',

                   borderWidth: '8px'

               }, 2000, 'Tween.Bounce.easeIn', {

                   start: function (el) { el.innerHTML = 'start!'; },

                   complete: function (el) { el.innerHTML = 'Completed!'; }

               }

        );

       </script>

</body>

</html>

 

 

 

作者 huajs

...

本文由澳门新萄京发布于澳门新萄京最大平台,转载请注明出处:澳门新萄京:javascript兑现十六进制颜色值,200八

上一篇:澳门新萄京入门基础,以及凭仗注入中代码压缩 下一篇:没有了
猜你喜欢
热门排行
精彩图文