<!DOCTYPE html>
<html lang="ru">
<head>
<style>
.window_show {
display: none;
z-index: 1000;
position: fixed;
width: 200px; height: auto;
right: 20px;
bottom: 20px;
padding: 15px;
text-align: center;
border-radius: 10px;
}
.green {
color: #fff;
background: #36549a;
border: 3px solid #7f98c0;
}
.green a {
color: #fff;
}
</style>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var over = 1;
var rnd = function (min, max){
return Math.floor(Math.random() * (max*1000 - min*1000)) + min*1000;
};
function sh(){
if(over) $('.window_show').toggle('drop');
}
if(!localStorage.getItem('flag0')){
setTimeout(sh, 5000);
if(!localStorage.getItem('flag0')) var nn = setTimeout(function ff(){
sh();
if(!localStorage.getItem('flag0')) nn = setTimeout(ff, rnd(1, 10)); // диапазон 1-10 сек
},10000);
}
$('#off').click(function(){
localStorage.setItem('flag0', 1);
});
$('.window_show').mouseover(function(){
over = 0;
});
$('.window_show').mouseout(function(){
over = 1;
});
});
</script>
</head>
<body>
<div class='window_show green'>Заказ удален<button id="off">Отключить уведомление</button></div>
</body>
</html>
|
CORONER,
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<style>
.window_show {
display: none;
z-index: 1000;
position: fixed;
width: 200px; height: auto;
right: 20px;
bottom: 20px;
padding: 15px;
text-align: center;
border-radius: 10px;
}
.green {
color: #fff;
background: #36549a;
border: 3px solid #7f98c0;
}
.green a {
color: #fff;
}
.window_show.act{
display: block;
}
</style>
</head>
<body>
<div class='window_show green'>Заказ удален<button id="off">Отключить уведомление</button></div>
<script>
window.addEventListener("DOMContentLoaded", function() {
var div = document.querySelector(".window_show"), hide = "abcd", i = 0, s = ["block", "none"], t;
function rnd() {
return 1000 + (Math.random() * 15000 | 0);
}
function clear() {
window.clearTimeout(t);
}
function getItem() {
return localStorage.getItem(hide);
}
function show() {
clear();
i ^= 1;
div.style.display = s[i];
!getItem() && (t = window.setTimeout(show, i ? rnd() : 5000));
}
!getItem() && show();
div.addEventListener("click", function() {
localStorage.setItem(hide, "hide");
show();
});
div.addEventListener("mouseenter", clear);
div.addEventListener("mouseleave", show);
});
</script>
</body>
</html>
|
Последний вопрос. Подскажите, как сделать так, чтобы только появление было рандомным, а исчезновение всегда через 5 секунд?
if(!localStorage.getItem('flag0')) var nn = setTimeout(function ff(){
sh(5000);
Таким образом? |
Цитата:
|
| Часовой пояс GMT +3, время: 11:58. |