【发布时间】:2018-08-03 22:29:52
【问题描述】:
所以我在 angular2 中有这个应用程序,我需要在其中水平滚动组件,但使用左右按钮。因此,我需要为每个向右或向左滚动内容的按钮提供一个功能。我需要这样的东西:
我尝试使用 document.getElementById('myscrolldiv').animate({ scrollLeft: "-=" + 250 + "px"; },但 Angular 无法识别 animate 行。
所以我正在寻找一种使用按钮而不是使用 jquery 水平滚动的不同方式。有什么方法可以用角度做到这一点?
这是我的html
<div class="container">
<div class="side">
<mat-icon (click)="scrollLeft()">keyboard_arrow_left</mat-icon>
</div>
<div id="widgetsContent" class="middle">
<div class="scrolls">
<div class="info-widget">
WIDGET
</div>
<div class="info-widget">
WIDGET
</div>
<div class="info-widget">
WIDGET
</div>
<div class="info-widget">
WIDGET
</div>
<div class="info-widget">
WIDGET
</div>
<div class="info-widget">
WIDGET
</div>
</div>
</div>
<div class="side">
<mat-icon (click)="scrollRight()">keyboard_arrow_right</mat-icon>
</div>
</div>
这是我的css
.container {
display: flex;
height: 22.5vh !important;
}
.side {
width: 50px;
height: 22.5vh !important;
}
.middle {
flex-grow: 1;
height: 22.5vh !important;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
那么,如何按按钮左右滚动?请帮忙。
【问题讨论】:
-
你的JS代码在哪里?
-
我在角组件中使用打字稿。函数 scrollLeft() 和 scrollRight() 现在是空的,但我需要一个不使用 JQuery 的滚动函数
-
您写道:“我尝试使用
document.getElementById('myscrolldiv')”。但是我在您的 HTML 代码中没有看到任何带有id="myscrolldiv"的元素。你真的了解自己在做什么吗?
标签: html css angular typescript