仿安卓的手机网页版toast
来源:互联网 发布:淘宝支付方式有哪些 编辑:程序博客网 时间:2024/04/28 01:57
1.先写好toast的js代码:
/**
* 模仿android里面的Toast效果,主要是用于在不打断程序正常执行的情况下显示提示数据
* @param config
* @return
*/
var Toast = function(config){
this.context = config.context==null?$('body'):config.context;//上下文
this.message = config.message;//显示内容
this.time = config.time==null?6000:config.time;//持续时间
this.left = config.left;//距容器左边的距离
this.top = config.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 toastMessageWidth = $('#toastMessage').innerWidth();
var toastMessageHeight = $('#toastMessage').innerHeight();
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var newWidth = (windowWidth - toastMessageWidth - 80) / 2 + "px";
var newHeight = (windowHeight - toastMessageHeight - 80) / 2 + "px";
msgEntity.css({'left':newWidth,'z-index':'999999','top':newHeight,'background-color':'black','color':'white',
'padding':'30px','font-size':'18px','border':'3px solid #f8c26d'});
},
//显示动画
show :function(){
msgEntity.fadeIn(this.time/2);
msgEntity.fadeOut(this.time/2);
}
}
function toastFunction(messageString){
new Toast({context:$('body'),message:messageString}).show();
}
2.先在你的html主页中添加jquery库和一下样式:
<style type="text/css">
#toastMessage{
position: absolute;
border-radius: 15px;
cursor:pointer;
}
</style>
3.如何调用:
toastFunction("成功调用!");
- 仿安卓的手机网页版toast
- Toast in Web,网页版Toast实现
- 网页中android Toast效果的实现
- 网页中android Toast效果的实现
- WebView网页版的手机app
- 手机网页的HTML
- 小米手机谈Toast
- 手机应用Toast不显示问题的解决
- 解决魅族手机不能Toast提示的方法
- 解决魅族手机不能Toast提示的方法--binbinYang
- 手机自适应的网页效果
- 网页版Android手机时钟网页特效
- 手机浏览器,怎么访问电脑版的网页?
- chrome查看手机版网页
- 华为手机无法弹出Toast
- 自动适配手机网页 适配手机的网站网页 网页自动适配
- 手机软件与手机网页的制作本钱
- 网页自适应手机、电脑屏幕的设置方法
- 欢迎使用CSDN-markdown编辑器
- Scala開發教程(1): 開始神奇的Scala編程之旅
- POJ 2187 Beauty Contest 凸包+旋转卡壳
- springmvc + maven + eclipse + mySql环境搭配
- ASP.NET Aspose.Cell控件使用教程
- 仿安卓的手机网页版toast
- Git服务器的搭建笔记
- Android学习笔记(11)————Android的私人文件夹的文件读写操作 .
- 准备Scala开发环境
- DOCTYPE 文档类型声明
- MSSQL附加数据库5120错误(拒绝访问)处理方法
- android view Touch
- Bmob使用案例常见异常总结
- 1. 第一个lavarel 项目