zoukankan      html  css  js  c++  java
  • H5_0034:toast提示

    html:

    <button id="showToast">此按钮是测试toast的例子</button>

    CSS:

            /*手机*/
            @media screen and (max-600px) {
    
    
                /* toast start */
                @-webkit-keyframes toastAnimation {
                    0% {
                        opacity: 1;
                    }
    
                    25% {
                        opacity: 0.75;
                    }
    
                    50% {
                        opacity: 0.5;
                    }
    
                    75% {
                        opacity: 0.25;
                    }
    
                    100% {
                        opacity: 0;
                    }
                }
    
                @keyframes toastAnimation {
                    0% {
                        opacity: 1;
                    }
    
                    25% {
                        opacity: 0.75;
                    }
    
                    50% {
                        opacity: 0.5;
                    }
    
                    75% {
                        opacity: 0.25;
                    }
    
                    100% {
                        opacity: 0;
                    }
                }
    
                .toast-message {
                    text-align: center;
                    color: #fff;
                    font-size: 16px;
                    width: 50%;
                    padding: 10px 0;
                    background-color: rgba(0, 0, 0, 0.5);
                    box-shadow: 0 8px 16px 0 rgba(51, 51, 51, 0.30);
                    border-radius: 8px;
                    position: fixed;
                    z-index: 9999;
                    left: 25%;
                    /*-webkit-animation:toastAnimation 1.5s ease-in 0s 1 normal;
                    */
                    /*animation:toastAnimation 1.5s ease-in 0s 1 normal;
                    */
                }
    
                /* toast end */
    
            }
    
    
    
    
            /*平板*/
            @media screen and (min-600px) and (max-960px) {
    
                /* toast start */
                @-webkit-keyframes toastAnimation {
                    0% {
                        opacity: 1;
                    }
    
                    25% {
                        opacity: 0.75;
                    }
    
                    50% {
                        opacity: 0.5;
                    }
    
                    75% {
                        opacity: 0.25;
                    }
    
                    100% {
                        opacity: 0;
                    }
                }
    
                @keyframes toastAnimation {
                    0% {
                        opacity: 1;
                    }
    
                    25% {
                        opacity: 0.75;
                    }
    
                    50% {
                        opacity: 0.5;
                    }
    
                    75% {
                        opacity: 0.25;
                    }
    
                    100% {
                        opacity: 0;
                    }
                }
    
                .toast-message {
                    text-align: center;
                    color: #fff;
                    font-size: 20px;
                    width: 50%;
                    padding: 10px 0;
                    background-color: rgba(0, 0, 0, 0.5);
                    box-shadow: 0 8px 16px 0 rgba(51, 51, 51, 0.30);
                    border-radius: 8px;
                    position: fixed;
                    z-index: 9999;
                    left: 25%;
                    /*-webkit-animation:toastAnimation 1.5s ease-in 0s 1 normal;
                    */
                    /*animation:toastAnimation 1.5s ease-in 0s 1 normal;
                    */
                }
    
                /* toast end */
    
            }
    
    
    
            /*PC*/
            @media screen and (min-960px) {
    
    
                /* toast start */
                @-webkit-keyframes toastAnimation {
                    0% {
                        opacity: 1;
                    }
    
                    25% {
                        opacity: 0.75;
                    }
    
                    50% {
                        opacity: 0.5;
                    }
    
                    75% {
                        opacity: 0.25;
                    }
    
                    100% {
                        opacity: 0;
                    }
                }
    
                @keyframes toastAnimation {
                    0% {
                        opacity: 1;
                    }
    
                    25% {
                        opacity: 0.75;
                    }
    
                    50% {
                        opacity: 0.5;
                    }
    
                    75% {
                        opacity: 0.25;
                    }
    
                    100% {
                        opacity: 0;
                    }
                }
    
                .toast-message {
                    text-align: center;
                    color: #fff;
                    font-size: 22px;
                    width: 26%;
                    padding: 10px 0;
                    background-color: rgba(0, 0, 0, 0.5);
                    box-shadow: 0 8px 16px 0 rgba(51, 51, 51, 0.30);
                    border-radius: 8px;
                    position: fixed;
                    z-index: 9999;
                    left: 37%;
                    /*-webkit-animation:toastAnimation 1.5s ease-in 0s 1 normal;
                        */
                    /*animation:toastAnimation 1.5s ease-in 0s 1 normal;
                        */
                }
    
                /* toast end */
    
            }

    js:

    $("#showToast").click(function() {
        toastMsg('toast提示成功');
    });
    
    
    /* Toast --start */
    function toastMsg(msg) {
        if ($("div").is("#toastMessage")) {
            $("#toastMessage").remove();
        }
    
        var msgDiv = '<div id="toastMessage" class="toast-message">' +
            '<span>' + msg + '</span>' +
            '</div>';
        $("body").append(msgDiv);
    
        //set #toastMessage of top
        //计算屏幕的高度,并让toast提示框显示在屏幕的中间
        var screenHeight = window.innerHeight;
        var toastMessage = $("#toastMessage");
        var toastHeight = toastMessage.height();
        var top = (screenHeight / 2) - (toastHeight / 2) + "px";
        toastMessage.css("top", top);
    
        setTimeout(function() {
            $("#toastMessage").remove();
        }, 1500);
    }
    /* Toast --end */
    琥珀君的博客
  • 相关阅读:
    【vue开发问题-解决方法】(十一)数据双向绑定导致修改数据格式原数据绑定出错
    【JavaScript】使用url下载文件,解决chrome浏览器自动识别图片打开问题。
    我的转行之路(电气转IT)------2018阿里校招面经
    关于Class.getResource和ClassLoader.getResource的路径问题
    protected修饰符详解
    为什么i=i++后,i的值不变(深入解析)
    Java中的初始化详细解析
    再谈抽象类(感觉理解的更深了)
    数据类型总结(干货)
    Java的接口和抽象类深入理解
  • 原文地址:https://www.cnblogs.com/eliteboy/p/12499116.html
Copyright © 2011-2022 走看看