jquery 遮罩層顯示img

來源:互聯網
上載者:User

標籤:pointer   tail   src   ext   設定   思路   item   cli   ref   

如果點擊iframe中的image顯示整個頁面的遮罩層,可參考如下:

http://blog.csdn.net/shiaijuan1/article/details/70160714

具體思路就是,頂層添加dom對象,用來顯示資訊,預設隱藏,需要時在iframe中調用,寬高設定為100%。

實現如下:

   //遮罩層    .showmask {            position: fixed;            z-index: 99;            width: 100%;            height: 100%;            background-color: silver;            top: 0px;            left: 0px;            opacity: 0.5;        }             .showmasklayer {            position: absolute;            z-index: 168;            top: 0px;            left: 0px;            min-width: 100%;            min-height: 100%;            display: flex;            justify-content: center;            align-items: center;        }       //關閉按鈕        .showmaskclose {            background-color: red;            color: white;            border: 2px solid gray;            position: fixed;            z-index: 288;            top: 0px;            right: 0px;            cursor: pointer;            height: 30px;            width: 30px;            font-size: large;            font-weight: bold;            text-align: center;            display: flex;            justify-content: center;            align-items: center;        }

iframe中調用如下:

 $(function () {        $("#image").on("click", function () {            //判斷是否已經添加過遮罩層dom            if ($(".showmaskclose", window.top.document).length == 0) {                //附加遮罩層dom                $("body", window.top.document).append("<div class=‘showmaskclose‘>×</div>").append("<div class=‘showmask‘></div>").append("<div class=‘showmasklayer‘></div>")                //附加後綁定事件                $(".showmaskclose", window.top.document).on("click", function () { htsHide(); })                $(".showmask", window.top.document).on("dblclick", function () { htsHide(); })                $(".showmasklayer", window.top.document).on("dblclick", function () { htsHide(); })                //添加圖片                $(".showmasklayer", window.top.document).append("<img src=‘" + this.src + "‘ />")            }            else {                //遮罩層dom顯示                $(".showmaskclose", window.top.document).show();                $(".showmask", window.top.document).show();                $(".showmasklayer", window.top.document).show();                //切換圖片                $(".showmasklayer > img", window.top.document).attr(‘src‘, this.src);            }        });    });    function htsHide() {        //遮罩層隱藏        $(".showmask", window.top.document).hide();        $(".showmaskclose", window.top.document).hide();        $(".showmasklayer", window.top.document).hide();    }

 

jquery 遮罩層顯示img

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.