javascript經典效果(五)

quguiliang 13年前發布 | 1K 次閱讀

五 接收鍵盤指令的腳本:


 

<DIV class=blockcode>

<DIV id=code13>

  1. <SCRIPT language="JavaScript">

  2. <!--

  3. var hotkey=97

  4. var destination="

  5. if (document.layers)

  6. document.captureEvents(Event.KEYPRESS)

  7. function backhome(e){

  8. if (document.layers){

  9. if (e.which==hotkey)

  10. window.location=destination

  11. }

  12. else if (document.all){

  13. if (event.keyCode==hotkey)

  14. window.location=destination

  15. }

  16. }

  17. document.onkeypress=backhome

  18. //-->

  19. </SCRIPT>

  20. onkeydown="javascript:onenter();"

  21. function onenter(){

  22. if(event.keyCode==13){

  23. alert("回車");

  24. }

  25. }
  26. </OL></DIV>復制代碼</DIV>


     

    六 讓你的文本鏈接漸隱漸顯:


     

    <DIV class=blockcode>

    <DIV id=code14>

    1. <META NAME="Description" CONTENT="">

    2. </HEAD>

    3. <BODY>

    4. <script language="javascript" type="text/javascript">

    5. startColor = "#671700"; // 定義鏈接顏色

    6. endColor = "#D8D1C5";  // 定義要漸變到最后的顏色

    7. stepIn = 17;

    8. stepOut = 23;

    9. /*

    10. 定義是否讓所有的文本鏈接自動漸變,true為是,false為否

    11. */

    12. autoFade = true;  

    13. /*

    14. 在這里定義css樣式里的類class:fade,如果為true,那么你要將要漸變的鏈接上加上此fade樣式

    15. */

    16. sloppyClass = false;

    17. hexa = new makearray(16);

    18. for(var i = 0; i < 10; i++)

    19.     hexa[i] = i;

    20. hexa[10]="a"; hexa[11]="b"; hexa[12]="c";

    21. hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

    22. document.onmouseover = domouseover;

    23. document.onmouseout = domouseout;

    24. startColor = dehexize(startColor.toLowerCase());

    25. endColor = dehexize(endColor.toLowerCase());

    26. var fadeId = new Array();

    27. function dehexize(Color){

    28. var colorArr = new makearray(3);

    29. for (i=1; i<7; i++){

    30.   for (j=0; j<16; j++){

    31.    if (Color.charAt(i) == hexa[j]){

    32.     if (i%2 !=0)

    33.      colorArr[Math.floor((i-1)/2)]=eval(j)*16;

    34.     else

    35.      colorArr[Math.floor((i-1)/2)]+=eval(j);

    36.    }

    37.   }

    38. }

    39. return colorArr;

    40. }

    41. function domouseover() {

    42.   if(document.all){

    43.    var srcElement = event.srcElement;

    44.    if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1))

    45.         fade(startColor,endColor,srcElement.uniqueID,stepIn);      

    46.    }

    47. }

    48. function domouseout() {

    49.   if (document.all){

    50.    var srcElement = event.srcElement;

    51.     if ((srcElement.tagName == "A" && autoFade) || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1))

    52.         fade(endColor,startColor,srcElement.uniqueID,stepOut);

    53.     }

    54. }

    55. function makearray(n) {

    56.     this.length = n;

    57.     for(var i = 1; i <= n; i++)

    58.         this[i] = 0;

    59.     return this;

    60. }

    61. function hex(i) {

    62.     if (i < 0)

    63.         return "00";

    64.     else if (i > 255)

    65.         return "ff";

    66.     else

    67.        return "" + hexa[Math.floor(i/16)] + hexa[i%16];}

    68. function setColor(r, g, b, element) {

    69.       var hr = hex(r); var hg = hex(g); var hb = hex(b);

    70.       element.style.color = "#"+hr+hg+hb;

    71. }

    72. function fade(s,e, element,step){

    73. var sr = s[0]; var sg = s[1]; var sb = s[2];

    74. var er = e[0]; var eg = e[1]; var eb = e[2];

    75. if (fadeId[0] != null && fade[0] != element){

    76.   setColor(sr,sg,sb,eval(fadeId[0]));

    77.   var i = 1;

    78.   while(i < fadeId.length){

    79.    clearTimeout(fadeId[i]);

    80.    i++;

    81.    }

    82.   }

    83.   

    84.     for(var i = 0; i <= step; i++) {

    85.      fadeId[i+1] = setTimeout("setColor(Math.floor(" +sr+ " (( " +step+ " - " +i+ " )/ " +step+ " ) + " +er+ " (" +i+ "/" +

    86.    step+ ")),Math.floor(" +sg+ " (( " +step+ " - " +i+ " )/ " +step+ " ) + " +eg+ " (" +i+ "/" +step+

    87.    ")),Math.floor(" +sb+ " ((" +step+ "-" +i+ ")/" +step+ ") + " +eb+ " (" +i+ "/" +step+ ")),"+element+");",i*step);

    88.   }

    89. fadeId[0] = element;

    90. }

    91. </script>

    92. </BODY>

    93. </HTML>

    94. <A HREF="">讓你的文本鏈接漸隱漸顯</A>
    95. </OL></DIV>復制代碼</DIV>

 本文由用戶 quguiliang 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!