简体   繁体   English

几秒钟后通知开/关

[英]Notification On/Off after few seconds

I'm a beginner with JavaScript and doing some exercise.我是 JavaScript 的初学者并做一些练习。 When I add a new movie a notification is showing up after 0.5seconds, but I'm not sure afterward how can I set a time-interval of 2 seconds to hide the notification.当我添加新电影时,会在 0.5 秒后显示通知,但我不确定之后如何设置 2 秒的时间间隔来隐藏通知。 Any help is appreciated!任何帮助表示赞赏!

 // Notification function notify(){ setTimeout(function(){ document.getElementById('notificationAddMovie').style.display = 'block'},500); }
 /* Notification */ #notificationAddMovie{ display: none; position:fixed; padding:1rem; bottom:10px; left:10px; background-color:#621940; color:#FFF; font-family: helvetica; border-radius:3px; }
 <!-- Movie Add Box--> <div id = 'notificationAddMovie'> <p>Successfully added!</p> </div>

function notify(){
    setTimeout(function(){
        document.getElementById('notificationAddMovie').style.display = 'block'
    }, 500);
    
    setTimeout(function(){
        document.getElementById('notificationAddMovie').style.display = 'none'
    }, 2000);
}

Is that what you need?那是你需要的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM