網頁中android Toast效果的實現

將以下代碼拷貝到html文件中即可測試

【轉載請註明出處:http://blog.csdn.net/zjbpku/article/details/7747655

<html>
<head>
<style type="text/css" >
#toast
{   
position: fixed;   
top: 200px;   
left: 50%;   
width: 200px;   
margin-left: -100px;   
border: 1px solid #666;   
background-color: #B1BCCF;   
padding: 10px 0 ;   
text-align:center;   
opacity: .9;   
  
-webkit-transition: opacity 0.5s ease-out ;
-moz-transition: opacity 0.5s ease-out; 
-ms-transition: opacity 0.5s ease-out;  
-o-transition: opacity 0.5s ease-out; 
transition: opacity 0.5s ease-out;   
<!--
/*The good stuff */  
-webkit-transition: opacity 0.5s ease-out; /* Saf3.2+, Chrome */  
-moz-transition: opacity 0.5s ease-out; /* FF4+ */  
-ms-transition: opacity 0.5s ease-out; /* IE10? */  
-o-transition: opacity 0.5s ease-out; /* Opera 10.5+ */  
transition: opacity 0.5s ease-out;   

-->
}
</style>

<script type="text/javascript">   
var intervalCounter = 0;   
function hideToast()
{     
var alert = document.getElementById("toast");   
alert.style.opacity = 0;   
clearInterval(intervalCounter);   
}   
function drawToast(message)
{   
var alert = document.getElementById("toast");   
if (alert == null)
{   
var toastHTML = '<div id="toast">' + message + '</div>';   
document.body.insertAdjacentHTML('beforeEnd', toastHTML);   
}   
else
{   
alert.style.opacity = .9;  
}   
intervalCounter = setInterval("hideToast()", 1000);   
}   
function save()
{   
drawToast("Toast······");   
}   
</script>   
</head>
<body>
<button οnclick="save()">Toast</button> 
<p>Toast</p>
<body>

</html>

<hr />

向博主發送郵件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章