js+css实现浮层

js+css实现浮层


<!DOCTYPE html>
<html>
<head>
<style>

</style>
<script>
//自定义弹框
function Toast(msg,duration){
     duration = isNaN(duration) ? 3000 : duration;
            var m = document.createElement('div');
            m.innerHTML = "<span style='padding:20%'>" + msg + "</span>";
            m.style.cssText = "width:50%;padding:6%;min-width: 150px;opacity: 0.5;color: rgb(255, 255, 255);line-height: 30px;text-align: center;border-radius: 55px;position: fixed;top: 50%;left: 30%;z-index: 999999;background: rgb(0, 0, 0);font-size: 22px;";
            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>

代码可以直接拷贝试一下,改一下自己的样式即可

猜你喜欢

转载自blog.csdn.net/zhiyikeji/article/details/88044662