web 彈出框 類似 android的toast的資訊提示

來源:互聯網
上載者:User

web js的alert彈出框,有時候並不是我們想要的,但是有時候又想給方便使用的提示,看了android的toast提示框也可在web前端實現,下面是參考一個人的源碼稍作修改做的

// JavaScript Document//  prompt messagefunction  warn(msg,opt,left,top){if(opt){var obj = $("#"+opt);}new Toast({context:$('body'),message:msg},obj,left,top).show();}var Toast = function(config,obj,left,top){this.context = config.context==null?$('body'):config.context;//上下文this.message = config.message;//顯示內容this.time = config.time==null?3000:config.time;//期間this.left = config.left;//距容器左邊的距離this.top = (screen.availHeight/4)*3;//距容器上方的距離if(obj){this.left = obj.offset().left + left;this.top = obj.offset().top + top;}this.init();}var msgEntity;Toast.prototype = {//初始化顯示的位置內容等init : function(){$("#toastMessage").remove();//設定訊息體var msgDIV = new Array();msgDIV.push('<div id="toastMessage">');msgDIV.push('<span>'+this.message+'</span>');msgDIV.push('</div>');msgEntity = $(msgDIV.join('')).appendTo(this.context);//設定訊息樣式var left = this.left == null ? this.context.width()/2-msgEntity.find('span').width()/2 : this.left;var top = this.top == null ? '20px' : this.top;msgEntity.css({position:'absolute',top:top,'z-index':'99',left:left,'background-color':'black',color:'white','font-size':'12px',padding:'5px',margin:'5px','border-radius':'4px','-moz-border-radius':'4px','-webkit-border-radius':'4px',opacity:'0.5','font-family':'微軟雅黑'});//msgEntity.addClass(".toast");msgEntity.hide();},//顯示動畫show :function(){msgEntity.fadeIn(this.time/2);msgEntity.fadeOut(this.time/2);}}

聯繫我們

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