前端展示信息,类似Android的Toast

    <div id="toastDiv" class="toast">
        <span id="tipMsg"></span>
    </div>

前端页面html,随便找个地方放进去,后面利用css移动到屏幕中间


.toast{
position: fixed;
height: 100px;
width: 200px;
top:50%;
left:50%;
margin:-50px 0 0 -100px;
background-color: #c0c0c0;
z-index=10;
border-radius:10px 10px;
text-align: center;
padding: 20px;
display: none;

}
前端css,位置移至屏幕中间,不显示出来


function toastShow(msg,time){
var toast=$('#toastDiv');
var tipMsg=$('#tipMsg');
tipMsg.text(msg);
toast.fadeIn();
setTimeout(function(){
    toast.fadeOut();
}, time);

}
js代码,利用jquery的‘fadeIn()’,‘fadeOut()’方法来渐入检出,利用‘setTimeout()’使toast定时消失.


方法调用(两个参数,第一个是要显示的信息,第二个是展示的时间,单位是毫秒,这里1000表示1秒):

toastShow(data.msg, 1000);

效果展示
这里写图片描述
这里写图片描述

猜你喜欢

转载自blog.csdn.net/caser_hdmi/article/details/79409518
今日推荐