html5+css3实现手机toast提示
2016-07-28 16:54
429 查看
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>自定义Toast,类似于android的Toast</title>
<style>
body {
font-family: 'Lucida Grande', 'Helvetica', sans-serif;
}
</style>
<script>
//自定义弹框
function Toast(msg,duration){
duration=isNaN(duration)?3000:duration;
var m = document.createElement('div');
m.innerHTML = msg;
m.style.cssText="width:60%; min-width:150px; background:#000; opacity:0.5; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:5px; position:fixed; top:40%; left:20%; z-index:999999; font-weight:bold;";
document.body.appendChild(m);
setTimeout(function() {
var d = 0.5;
m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
m.style.opacity = '0';
setTimeout(function() { document.body.removeChild(m) }, d * 1000);
}, duration);
}
</script>
</head>
<body>
<button onclick="Toast('您点击了弹框按钮!',2000);">Toast</button>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>自定义Toast,类似于android的Toast</title>
<style>
body {
font-family: 'Lucida Grande', 'Helvetica', sans-serif;
}
</style>
<script>
//自定义弹框
function Toast(msg,duration){
duration=isNaN(duration)?3000:duration;
var m = document.createElement('div');
m.innerHTML = msg;
m.style.cssText="width:60%; min-width:150px; background:#000; opacity:0.5; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:5px; position:fixed; top:40%; left:20%; z-index:999999; font-weight:bold;";
document.body.appendChild(m);
setTimeout(function() {
var d = 0.5;
m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
m.style.opacity = '0';
setTimeout(function() { document.body.removeChild(m) }, d * 1000);
}, duration);
}
</script>
</head>
<body>
<button onclick="Toast('您点击了弹框按钮!',2000);">Toast</button>
</body>
</html>
相关文章推荐
- H5页面开发之页面基本结构布局
- Html5 web本地存储实例详解
- H5 capture 打开视频、图片、录音
- 功能强大的HTML5上传组件-Web Uploader
- 基于HTML5的多张图片上传
- Html5导航插件,支持水平/垂直展示
- HTMl5的sessionStorage和localStorage
- html5调用摄像头
- 33个优秀的HTML5应用演示 (转)
- 33个优秀的HTML5应用演示 (转)
- 来,做一个问卷调查(有抽奖!)
- H5页面调用拍照上传图片
- 移动页面HTML5自适应手机屏幕宽度
- h5页面上拉加载下拉刷新问题
- HTML5之本地存储
- H5成长之路 元素及文本对齐方式
- HTML5 Video标签的属性、方法和事件汇总介绍
- HTML5 Web API:postMessage
- Html5+Css3实现类似网易云音乐的移动版播放器
- 【整理】HTML5全局属性