<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Atea - Hero's Grave

    面向?qū)ο螅_源,框架,敏捷,云計(jì)算,NoSQL,商業(yè)智能,編程思想。

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      40 隨筆 :: 0 文章 :: 28 評(píng)論 :: 0 Trackbacks
    1."rich" textarea editor.
    前段時(shí)間有個(gè)霓虹燈的小項(xiàng)目。后臺(tái)用asp.net給硬件傳接口(具體怎樣就不清楚了),前臺(tái)網(wǎng)頁(yè)讓做個(gè)可即時(shí)變色的textarea editor,把內(nèi)容傳給后臺(tái)就行了。其實(shí)如果不要求即時(shí)變色的話,自定義個(gè)命名規(guī)則就行了。
    沒辦法只能上網(wǎng)搜。先試了document.selection,可惜只支持IE而且bug不少(比如不能隔行操作)。后來搜到了一些開源的editor,人家用純js寫的小框架,真是牛。
    自己也用iframe寫了個(gè)簡(jiǎn)單的,一般功能是沒問題了:

    程序目錄結(jié)構(gòu)
    img
      
    ***.gif
    js
      common.js
    iframe.html
    test.html

    test.html
     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     2    "http://www.w3.org/TR/html4/loose.dtd">
     3 <html>
     4 <head>    
     5     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     6     <style type="text/css"> 
     7         img{cursor:pointer;}
     8         .class1{
     9         border:solid 1px;
    10         width:600px;
    11         height:400px;   
    12         }
    13     </style> 
    14     <script type="text/javascript" src="js/common.js"></script>
    15     <title>iframe editor</title>
    16 </head>
    17 <body onload="init()">
    18 <form id="form1">
    19     
    20     <div style="width:600px">
    21         <div align=right style="float:right;">
    22             <img src="img/1.gif" onclick="chgFont()" title="Change Font!" />
    23             <img src="img/2.gif" onclick="addIMG()" title="Add Image!" />
    24             
    25         </div> 
    26     </div>    
    27         
    28     <iframe src="iframe.html" id="editor" class="class1"></iframe>  
    29     
    30     <div style="width:600px" align=right>
    31         <input type="button" id="button1" value="Get Editor Value" onclick="getDocValue()" />
    32     </div>     
    33 
    34 </form>
    35 </body>
    36 </html>

    iframe.html
    1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    2    "http://www.w3.org/TR/html4/loose.dtd">
    3 <html>
    4 <head>
    5     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    6 </head>  
    7 <body>Hello World! 啊啊</body>
    8 </html>

    common.js
     1 function $(tagid){
     2    return document.getElementById(tagid);
     3 }
     4 
     5 function getDocValue(){
     6     alert($("editor").contentWindow.document.body.innerHTML);    
     7 }
     8 
     9 function init(){
    10     var win = $("editor").contentWindow;
    11     win.document.designMode= "on";
    12     win.document.contentEditable = true;
    13     win.focus();    
    14 }
    15 
    16 function chgFont() {
    17     var win=$("editor").contentWindow;
    18     win.document.execCommand("ForeColor",false,"red");
    19     win.document.execCommand("FontSize",false,"10");
    20     win.focus();
    21 }
    22 
    23 function addIMG() {
    24     var win=$("editor").contentWindow;
    25     win.document.execCommand("InsertImage",false,"img/a.gif");
    26     win.focus();
    27 
    注:document.execCommand可以改變很多樣式,詳情請(qǐng)參照手冊(cè):)

    2.Advertisement Board.
    在CSDN看到的項(xiàng)目投標(biāo)的廣告滾動(dòng)條,用的是iframe + window.scrollBy,挺有意思的。
    自己把源碼做了點(diǎn)改進(jìn),并加了個(gè)暫停滾動(dòng)的功能:

    test.html
     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     2    "http://www.w3.org/TR/html4/loose.dtd">
     3 <html>
     4 <head>    
     5     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     6     <title>iframe scroll</title>
     7     <style type="text/css">
     8         iframe{margin: 0pt; width: 180px; height: 32px;}
     9     </style>
    10 </head>
    11 <body>
    12 <form id="form1">
    13     <h4>Exciting Advertisement Board</h4>
    14     <iframe src="iframe.html" scrolling="no" frameborder="1"></iframe>
    15 
    16 </form>
    17 </body>
    18 </html>

    iframe.html
     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     2    "http://www.w3.org/TR/html4/loose.dtd">
     3 <html>
     4 <head>
     5     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     6     <style type="text/css">
     7         *{margin:0;padding:0;}
     8         body {background:#F2F2FC;font:normal 12px verdana,sans-serif;}
     9         ul{list-style-type:none;}
    10         li{width:180px;}
    11         a{color:#03C;text-decoration:none;}
    12         a:hover{color:#F00;text-decoration:none;}
    13     </style>     
    14 </head>
    15 <body>
    16     <ul id="scrollCon" onmouseover="suspend()" onmouseout="resume()">        
    17         <li>Hello!</li>
    18         <li><href="aaa">I'm aaa.</a></li>
    19         
    20         <li>Hi!</li>
    21         <li><href="bbb">I'm bbb.</a></li>
    22         
    23         <li>How are you!</li>
    24         <li><href="ccc">I'm ccc.</a></li>
    25     </ul>
    26 
    27     <script language="javascript">
    28         var con=document.getElementById("scrollCon");
    29         var items=con.getElementsByTagName("li");
    30         var item_count=items.length/2;
    31         var line_height=items[0].offsetHeight;
    32         var timer1,timer2;
    33         var step=0,cstep=0;
    34         var isPlayed=false;
    35 
    36         function startScroll(){
    37             timer1=setInterval("doScroll()",40);//數(shù)值越大,滾動(dòng)越慢
    38         }
    39         function doScroll(){            
    40             window.scrollBy(0,2);//滾動(dòng)幅度
    41             step++;
    42             if(step>=line_height) {
    43                 clearInterval(timer1);
    44                 step=0;
    45                 cstep++;
    46                 if(cstep>=item_count){
    47                     cstep=0;
    48                     window.scrollTo(0,0);
    49                 }
    50             }
    51         }
    52         function start(){
    53             if(isPlayed)return;
    54             isPlayed=true;                        
    55             timer2=setInterval("startScroll()",3000);//滾動(dòng)間隔
    56         }
    57         function suspend(){
    58             clearInterval(timer1);
    59             clearInterval(timer2);
    60         }        
    61         function resume(){
    62             timer2=setInterval("startScroll()",3000);
    63         }
    64         function stop(){
    65             isPlayed=false;
    66             clearInterval(timer2);
    67         }
    68         
    69         start();
    70     </script>
    71 </body>
    72 </html>

    posted on 2008-08-25 18:46 Atea 閱讀(2731) 評(píng)論(0)  編輯  收藏 所屬分類: Javascript

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲免费网站在线观看| 亚洲国产高清视频| 美女尿口扒开图片免费| 免费无码黄动漫在线观看| 亚洲精品国产精品国自产网站| 国产福利在线观看免费第一福利| 亚洲成人午夜电影| 西西大胆无码视频免费| 亚洲精品人成网线在线播放va| 午夜视频在线在免费| 亚洲暴爽av人人爽日日碰| 免费国产a国产片高清网站| 永久免费观看黄网站| 亚洲深深色噜噜狠狠爱网站 | MM1313亚洲精品无码久久| 国产精品久久免费视频| 一级毛片大全免费播放下载 | 亚洲国产精品自在在线观看| 国产精品成人免费福利| 亚洲日本VA午夜在线影院| 亚洲天堂2017无码中文| 成人毛片免费观看| 日日摸夜夜添夜夜免费视频| 亚洲午夜无码久久久久| 中国xxxxx高清免费看视频| 亚洲日本va一区二区三区| 亚洲色偷偷综合亚洲AV伊人| 高清一区二区三区免费视频| 亚洲国产成人爱av在线播放| a级成人毛片免费图片| 亚洲成在人线电影天堂色| 全黄性性激高免费视频| 久草福利资源网站免费| 亚洲av永久中文无码精品| 伊人久久综在合线亚洲91| 在线视频精品免费| 美女黄频a美女大全免费皮| 亚洲AV人人澡人人爽人人夜夜| 国语成本人片免费av无码| igao激情在线视频免费 | 亚洲乱妇老熟女爽到高潮的片|