zoukankan      html  css  js  c++  java
  • js 实现 toast

    点击页面空白地方试试

    .bw-toast{
        box-sizing: border-box;
        position: fixed;
        right: calc(50% - 200px);
        height: 36px;
         400px;
        border-radius: 3px;
        color: #fff;
        font-size: 16px;
        line-height: 1;
        padding: 10px 10px;
        background-color: #000;
        transition: all .1s;
    }
    

      

    var bw = {};
    bw.list = [];
    bw.toast = function( txt ){
    	var i = 38;
    	if( bw.list.length ){
    		bw.list.forEach( function(element, index) {
    			element.setAttribute('style', 'bottom: '+(bw.list.length-index)*i+'px;');
    		});
    	}
    	var toast = document.createElement('div');
    	toast.classList = 'bw-toast';
    	toast.setAttribute('style', 'bottom: -36px;');
    
    	var msg = document.createTextNode(txt);
    	toast.append(msg);
    	bw.list.push(toast);
    	document.body.append(toast);
    
    	setTimeout(function(){
    		toast.setAttribute('style', 'bottom: 0px;');
    	}, 0)
    	setTimeout(function(){
    		toast.parentNode.removeChild(toast);
    		bw.list.shift();
    	}, 2000)
    }
    
    document.body.onclick = function(){
    	bw.toast(new Date())
    }
    

      

  • 相关阅读:
    set的使用
    this.$watch(),this.$set(),this.$nextTick()=>{})
    web 错误代码解析
    samba 问题解决
    Linux postfix配置方法
    Linux rhcsa认证考试试题模拟
    Linux 使用nmcli配置网络
    Linux 链路聚合
    Linux ISCSI服务配置
    Linux Apache配置https访问
  • 原文地址:https://www.cnblogs.com/luozhangshuai/p/8109322.html
Copyright © 2011-2022 走看看