JQuery學習一

來源:互聯網
上載者:User

標籤:jquery   強制回應視窗   

    

    學習JQuery,如何建立、調用和關閉強制回應視窗。

(document).ready(function() {/* Background Resizer-背景自適應瀏覽器大小 */$("#bodyBackground").ezBgResize();/* modal windows */$('a.modal').click(function() {/*attr-擷取屬性值,例如tagName*/        var modalID = $(this).attr('rel'); // get the name of the modal                /* fade in the modal window and add a close button to it *//**fadeIn-淡入已隱藏的元素*prepend-在被選元素的開頭插入內容*/        $('#' + modalID).fadeIn().prepend('<a href="#" class="close"><img src="grfx/close_button.png" class="close_button" title="Close Window" alt="Close" /></a>');        /*          * define the margins so that the modal is centered properly on the screen         * we add 80px to the height/width to accomodate for the padding and border         * width defined in the css         */        var modalMarginTop = ($('#' + modalID).height() + 80) / 2;        var modalMarginLeft = ($('#' + modalID).width() + 80) / 2;        /* apply the margins to the modal window */        $('#' + modalID).css({            'margin-top' : -modalMarginTop,            'margin-left' : -modalMarginLeft        });        /* fade in the shade! (tired of the cheesy jokes yet?) *//*append-被選元素的結尾插入內容。*/        $('body').append('<div id="modalShade"></div>'); // add the shade layer to bottom of the body        $('#modalShade').css('opacity', 0.7).fadeIn(); // set the opacity with jQuery to avoid all of the nasty CSS needed for IE        return false; // keep the link from acting naturally    });    /*     * close the modal and pull down the shade     */ /*live-綁定事件函數,文法是$(selector).live(event,data,function),live函數不支援DOM遍曆*/    $('a.close, #modalShade').live('click', function() { // clicking on the close or shade layer/*parent-返回被選元素的直接父元素,方法只會向上一級對 DOM 樹進行遍曆*/    var thisModalID = $('a.close').parent().attr('id');        $('#modalShade, #'+thisModalID).fadeOut(function() {/* remove-刪除被選元素(及其子項目),該方法也可接受一個參數,允許您對被刪元素進行過濾。例如指定過濾class為del的remove('.del')*/            $('#modalShade, a.close').remove();  // remove the shade and the close button        });        return false;    });


JQuery學習一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.