CSS 3模仿Android 中的toast效果
在Android中,可以使用toast搞出一个信息提示的效果,在CSS 3中,其实也可以
模仿一下,如下代码,先是CSS:
- #toast{
- position: fixed;
- top: 20px;
- left: 50%;
- width: 200px;
- margin-left: -100px;
- border: 1px solid #666;
- background-color: #B1BCCF;
- padding: 10px 0 ;
- text-align:center;
- opacity: .9;
- /*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;
- }
之后设计一个按钮,然后设计JAVASCRIPT代码如下:
- <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("Item saved");
- }
- </script>
- <button onclick="save()">Save</button>
可惜只能在非IE下运行了。
相关推荐
impress 2020-08-26
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20