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

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

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

    子在川上曰

      逝者如斯夫不舍晝夜
    隨筆 - 71, 文章 - 0, 評論 - 915, 引用 - 0
    數(shù)據(jù)加載中……

    用AJAX實現(xiàn)氣泡提示


                                        文/陳剛 www.chengang.com.cn (轉(zhuǎn)載請注明)

    這個效果的實現(xiàn)是以網(wǎng)站http://www.panic.com/coda/為模仿對象(選擇Download可以看到氣泡提示效果),然后重新用Rails中的prototype.js來實現(xiàn)。

    HTML頁面的代碼:
    <span id="content_<%=o.id%>" style="display:none">
        
    <!-- Download Popup style=opacity: 0; visibility: hidden;-->
    <table style="top:500px; left:600px;" class="popup">
      <tbody>
        <tr>
          <td class="corner" id="topleft"></td>
          <td class="top"></td>
          <td class="corner" id="topright"></td>
        </tr>
        <tr>
          <td class="left"></td>
          <td><table class="popup-contents">
            <tbody>
                <tr>
                  <td><%=o.content%></td>
                </tr>
            </tbody>
          </table></td>
          <td class="right"></td>    
        </tr>
        <tr>
          <td id="bottomleft" class="corner"></td>
          <td class="bottom"><img src="/images/bubble-tail2.png" alt="popup tail" height="29" width="30"></td>
          <td class="corner" id="bottomright"></td>
        </tr>
      </tbody>
    </table>
    <!-- end download popup -->
    </span>


    CSS的代碼(涉及到的相關(guān)圖片:bubble.rar):
    /* Bubble pop-up */
    .popup {
        position: absolute;
        z
    -index: 50;
        border
    -collapse: collapse;
           
    /* width:500px;
        visibility: hidden; 
    */
    }

    .popup td.corner {height: 15px;    width: 19px;}
    .popup td#topleft { background
    -image: url(/images/bubble-1.png); }
    .popup td.top { background
    -image: url(/images/bubble-2.png); }
    .popup td#topright { background
    -image: url(/images/bubble-3.png); }
    .popup td.left { background
    -image: url(/images/bubble-4.png); }
    .popup td.right { background
    -image: url(/images/bubble-5.png); }
    .popup td#bottomleft { background
    -image: url(/images/bubble-6.png); }
    .popup td.bottom { background
    -image: url(/images/bubble-7.png); text-align: center;}
    .popup td.bottom img { display: block; margin: 
    0 auto; }
    .popup td#bottomright { background
    -image: url(/images/bubble-8.png); }

    .popup table.popup
    -contents {
        font
    -size: 12px;
        line
    -height: 1.2em;
        background
    -color: #fff;
        color: #
    666;
        font
    -family: "Lucida Grande""Lucida Sans Unicode""Lucida Sans", sans-serif;
        }

    table.popup
    -contents th {
        text
    -align: right;
        text
    -transform: lowercase;
        }
        
    table.popup
    -contents td {
        text
    -align: left;
        }

    然后給需要氣泡提示的加上鼠標事件:
     <span class="l1" onmouseover="Element.show('content_<%=o.id%>')" onmouseout="Element.hide('content_<%=o.id%>')"><%=article_link_to(o.title,o.id)%></span>



    二、繼續(xù)改進
    氣泡提示的外圍HTML表格代碼可以改由javascript來動態(tài)生成,這樣可以縮小一些頁面的總HTML大小。

    HTML頁面代碼改為:
    <span id="content_<%=o.id%>" style="display:none"><%=o.content%></span>
    其他想法:本來打算把文章內(nèi)容(氣泡顯示的內(nèi)容),直接傳入javascript函數(shù)showPopup里。但由于其字符串較復雜,需要對一些特殊字符進行轉(zhuǎn)義才可以當成字符串傳入,而轉(zhuǎn)義需要通寫Rails方法來實現(xiàn),大量的字符搜索替換恐怕會增加服務器的負擔。所以這里還是用一個html元素暫存氣泡內(nèi)容。


    然后給需要氣泡提示的加上鼠標事件。
        <span class="l1" onmouseover="showPopup('content_<%=o.id%>',event);" onmouseout="hidePopup()"><%=article_link_to(o.title,o.id)%></span>

    CSS的代碼不變。

    寫兩個javascript函數(shù):
    function showPopup(element_id,event){
      
    var div = createElement("div");  
      div.id 
    = "popup";
      
    //div.style.display="none";
      var popup = $(element_id);
      
    //取得鼠標的絕對坐標
      var evt = event ? event : (window.event ? window.event : null);  
      
    var x = Event.pointerX(evt)+5;
      
    var y = Event.pointerY(evt)+5;
      div.innerHTML
    ='\
            
    <table style="top:' + y + 'px; left:' + x + 'px;" class="popup">\
              
    <tbody>\
                
    <tr>\
                  
    <td class="corner" id="topleft"></td>\
                  
    <td class="top"></td>\
                  
    <td class="corner" id="topright"></td>\
                
    </tr>\
                
    <tr>\
                  
    <td class="left"></td>\
                  
    <td><table class="popup-contents">\
                    
    <tbody>\
                        
    <tr>\
                          
    <td>+ popup.innerHTML + '</td>\
                        
    </tr>\
                    
    </tbody>\
                  
    </table></td>\
                  
    <td class="right"></td>\
                
    </tr>\
                
    <tr>\
                  
    <td id="bottomleft" class="corner"></td>\
                  
    <td class="bottom"><!--<img src="/images/bubble-tail2.png" alt="popup tail" height="29" width="30">--></td>\
                  
    <td class="corner" id="bottomright"></td>\
                
    </tr>\
              
    </tbody>\
            
    </table>';
      document.body.appendChild(div);
      
    //Element.show("popup");
    }

    function hidePopup(){
      Element.remove(
    "popup");
    }

    function createElement(element) {
        if (typeof document.createElementNS != 'undefined') {
            return document.createElementNS('http://www.w3.org/1999/xhtml', element);
        }
        if (typeof document.createElement != 'undefined') {
            return document.createElement(element);
        }
        return false;
    }


    在javascript中漸顯Effect.Appear有一點問題,所以就沒再用。

    效果如下圖所示:






    posted on 2007-07-31 15:32 陳剛 閱讀(4355) 評論(7)  編輯  收藏 所屬分類: Rails&Ruby

    評論

    # re: 用AJAX實現(xiàn)氣泡提示  回復  更多評論   

    喜歡
    2007-09-04 13:32 | yukui

    # re: 用AJAX實現(xiàn)氣泡提示  回復  更多評論   

    可是你寫的不夠詳細啊,我看的不是很明白啊!能不能寫的更加清楚一些啊,老兄!!!!!!
    2007-09-07 15:28 | xiaowei

    # re: 用AJAX實現(xiàn)氣泡提示  回復  更多評論   

    確實不夠詳細,按照您的說法做不成啊。o是什么對象?article_link_to是什么?
    2007-09-11 14:41 | guest

    # re: 用AJAX實現(xiàn)氣泡提示  回復  更多評論   

    原來是差了一個prototype.js,大家如果有再使用這個的時候,不要忘了找一個prototype.js導入哦。謝謝樓主。東西很不錯!
    2007-09-11 16:23 | guest

    # re: 用AJAX實現(xiàn)氣泡提示  回復  更多評論   

    請問能夠?qū)懙酶敿氁稽c么?就像o.id之類的都是怎么來的?看不懂啊
    2007-10-17 17:07 | chengshuai

    # re: 用AJAX實現(xiàn)氣泡提示  回復  更多評論   

    如果方便的話能麻煩您把您文章中的源碼給我發(fā)一下么?我的郵箱
    chengshuai@yahoo.cn
    謝謝了!
    2007-10-17 17:08 | chengshuai

    # re: 用AJAX實現(xiàn)氣泡提示  回復  更多評論   

    如果方便的話能麻煩您把您文章中的源碼給我發(fā)一下么?我的郵箱
    lifuyun023@163.com
    謝謝了!
    2010-03-02 12:00 | 云中深海
    主站蜘蛛池模板: 亚洲欧洲自拍拍偷午夜色| 亚洲av中文无码乱人伦在线r▽| 亚洲日本乱码一区二区在线二产线 | 亚洲日本久久久午夜精品| 精品国产无限资源免费观看| 亚洲乱亚洲乱淫久久| 外国成人网在线观看免费视频| 国产AV无码专区亚洲AV毛网站| 成人久久免费网站| 久久国产亚洲观看| 中文字幕免费在线| 97在线免费视频| 亚洲欧洲日产国码av系列天堂| 中国一级特黄高清免费的大片中国一级黄色片| 亚洲av午夜成人片精品电影| 一级一级一片免费高清| 亚洲最大激情中文字幕| 久久九九AV免费精品| 亚洲一卡二卡三卡四卡无卡麻豆| 女人被男人躁的女爽免费视频| 亚洲av午夜电影在线观看| 亚洲av无码乱码在线观看野外| 91视频免费观看| 亚洲毛片免费观看| 国产青草视频免费观看97| 国产激情久久久久影院老熟女免费| 亚洲熟妇少妇任你躁在线观看无码 | 免费观看一区二区三区| 亚洲精品美女在线观看| 日本无吗免费一二区| 久久精品无码专区免费| 亚洲视频网站在线观看| 日产乱码一卡二卡三免费| 男女一边桶一边摸一边脱视频免费| 久久久久亚洲精品成人网小说| 午夜性色一区二区三区免费不卡视频 | 日韩a级毛片免费视频| 国产高清视频免费在线观看| 亚洲视频小说图片| 免费在线观看a级毛片| 久久中文字幕免费视频|