Web pop-up toast information tips like Android

Source: Internet
Author: User

The Web JS alert pop-up box, sometimes not what we want, but sometimes want to give users a friendly hint, look at the Android Toast hint box can also be implemented on the Web front-end, the following is a reference to a person's source code slightly modified to do

JavaScript Document//Prompt message function 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;//context This.message = config.message;//Display Content this.time = config.time==null?3000:config.time;//Duration This.left = config.left;//
	Distance from the left side of the container this.top = (SCREEN.AVAILHEIGHT/4) *3;//distance from the top of the container if (obj) {this.left = Obj.offset (). Left Plus left;
	This.top = Obj.offset (). Top + top;
} this.init ();
} var msgentity;
		Toast.prototype = {//Initialize the displayed location content Init:function () {$ ("#toastMessage"). Remove ();
		Set the message body var msgdiv = new Array ();
		Msgdiv.push (' <div id= ' Toastmessage ">");
		Msgdiv.push (' <span> ' +this.message+ ' </span> ');
		Msgdiv.push (' </div> ');
		Msgentity = $ (Msgdiv.join (')). Appendto (This.context); Set Message style 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 ': ' The ', 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 ': ' Microsoft Ya-hei '};
		Msgentity.addclass (". Toast");
	Msgentity.hide ();
		},///Show Animation show:function () {Msgentity.fadein (THIS.TIME/2);
	Msgentity.fadeout (THIS.TIME/2); }
		
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.