JS:遍历数组,在通知中依次显示每个项
JS: Iterate over array, display each item sequentially in a notification
我尝试遍历一个数组,在通知中依次显示每个项目:
- 从底部向上滑动,带有CSS动画
- 显示时延迟3秒
- 滑动到底部与css动画
- 下一项加载前的8秒间隔
同时,当鼠标停留在屏幕上时,通知应该保持在屏幕上,并且在鼠标离开时隐藏(经过第二次延迟)。
我有以下问题:
- 如何在css动画后创建3秒的延迟?
- 我如何依次遍历项目?在下面的代码中,它们会同时执行。
- 如何暂停和恢复动画?
$(function() {
var delay = 3000,
interval = 8000,
$el = $('#notification'),
data = [{
id: 1,
content: 'First Notification'
},
{
id: 2,
content: 'Second Notification'
},
{
id: 3,
content: 'Third Notification'
}];
$.each(data, function (i, item) {
console.log (item);
// add the content to the html
$el.html(item.content);
$el.addClass('in');
$el.one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) {
// animate in complete
console.log('in complete', i);
// add delay before slide out
$el.removeClass('in').addClass('out');
$el.one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) {
// animate out complete
console.log('out complete', i);
// add interval before next slide in
});
});
});
$el.on('mouseover', function () {
// pause the animation
});
$el.on('mouseout', function () {
// resume the animation
});
});
Demo
var delay = 3000,
interval = 8000 + delay,
$el = $('#notification'),
data = [{
id: 1,
content: 'First Notification'
},
{
id: 2,
content: 'Second Notification'
},
{
id: 3,
content: 'Third Notification'
}],
currentItem = 0 ,
timeoutTrack ,
intervalTrack;
showNextOne();
var intervalTrack = setInterval(function(){showNextOne();},interval);
function showNextOne()
{
$el.html(data[currentItem].content).addClass("in");
timeoutTrack = setTimeout(function()
{
$el.removeClass("in").addClass("out");
setTimeout(function(){$el.removeClass("out");},1500);
},delay);
if(currentItem +1 >= data.length)
currentItem = 0;
else
currentItem++;
}
$el.on("mouseenter",function()
{
if(timeoutTrack)
clearTimeout(timeoutTrack);
if(intervalTrack)
clearInterval(intervalTrack);
});
$el.on("mouseleave",function()
{
timeoutTrack = setTimeout(function()
{
$el.removeClass("in").addClass("out");
setTimeout(function(){$el.removeClass("out");},1500);
},delay);
intervalTrack = setInterval(function(){showNextOne();},interval);
});
相关文章:
- notify.js没有'如果另一个窗口被聚焦,则不显示通知
- 在ajax调用后在rails中显示通知
- Cordova:如何显示系统通知
- Toast通知未显示在右下角
- 通知权限被拒绝(桌面推送通知).通知弹出窗口不会't以镀铬显示
- Chrome扩展通知未显示contextMessage
- 重定向后在页面上显示通知
- 无法发送应用请求,显然已发送,但未显示通知用户
- 使用AngularFire创建用户并调用工厂以显示通知
- 单击“保存到CSV”按钮后显示通知(如果未安装Flash Player)
- 使用编码器点火器保存数据后显示通知
- 如何在用户移动到另一个页面时向用户显示通知而不保存数据
- 我如何显示通知每用户与jquery和php
- 我必须重新加载chrome扩展以显示通知
- 用于在浏览器标头中显示通知的选项
- 如何使用代码点火器在控制器的锚点内显示通知
- 如何根据在 HTML5 中使用服务器发送的事件检索的数据显示通知
- 显示通知直到超时除非悬停(jQuery)
- 如果表单包含单词,则显示通知
- 显示通知Chrome扩展