html - Angular 动画通知水平堆叠

标签 html css angularjs

我整天都在搜索,但没有找到解决此问题的方法。诚然,我对 Angular (和一般编码)非常陌生,但我发现的每个指南似乎都不起作用。

我正在尝试在屏幕顶部从右侧滑入显示小的通知消息(固定位置)。如果第二个通知在第一个通知消失(或手动关闭)之前出现,那么它会将第一个通知推到右边。这将在屏幕顶部水平显示所有通知。

我是否缺少一种简单的方法来做到这一点?那里有有用的指南或类似内容的片段吗?

我真的没有任何代码可以展示,因为我什至找不到起点。

最佳答案

这就是你的意思吗:

(注意 下面的例子在这个阶段没有使用 AngularJS)

var n = 0;
var notifications = document.getElementsByClassName('notification');
var button = document.getElementsByTagName('button')[0];

function addNotification() {
    if (n > (notifications.length - 1)) return;
    
    notifications[n].style.transform = 'translateX(0)';
    
    for (var i = (n - 1); i > -1; i--) {
        notifications[i].style.transform = 'translateX(' + ((n - i) * (1 + 120 + 1 + 4)) + 'px)';
    }
    
    n++;
}

button.addEventListener('click', addNotification, false);
body {
overflow-x: hidden;
}

.notification {
position: absolute;
top: 6px;
left: 6px;
display: inline-block;
width: 120px;
height: 24px;
line-height: 24px;
color: rgb(255, 255, 255);
font-size: 11px;
font-weight: bold;
text-align: center;
text-transform: uppercase;
background-color: rgb(223, 0, 0);
border: 1px solid rgb(191, 0, 0);
box-shadow: 2px 2px 2px rgb(0, 0, 0, 0.4);
transform: translateX(200vw);
transition: transform 1s ease-out;
}

button {
margin-top: 36px;
cursor: pointer;
}
<div class="notification">Notification 1</div>
<div class="notification">Notification 2</div>
<div class="notification">Notification 3</div>
<div class="notification">Notification 4</div>

<button type="button">Add Notification</button>

关于html - Angular 动画通知水平堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47612876/

相关文章:

css - 表单在 chrome 和 IE6 中显示不正确

javascript - 只是页面工作中的 ng-bind-html 之一

css - 悬停下拉按钮时如何更改插入符号的颜色

html - 线性渐变不覆盖整个图像(留下 ~1px 边框)

html - 如何在左、右菜单和导航栏保持不动的情况下使主要部分滚动?

html - 展开主 div 以适应内容 - CSS 故障排除

jquery - 从顶部滚动到设置的像素数后,div 变得固定,也只大于设置的窗口宽度,加上 border-bottom

javascript - 使用 CSS/JavaScript 安排动画?

html - 如何将 div 的左、右、上边距设置为相等

javascript - AngularJS n:n许诺和数据同步/排序