单击 div 水平滚动 angular 6
On click scroll div horizontally in angular 6
我正在为 css 使用 Angular 6 和 bootstrap 框架。我想在单击 left/right 按钮时水平滚动 div。
我想滚动下面的内容 div,章节名称可能包含一章或多于 1 章,即 1-10 章。如何实现点击 let 和右箭头按钮时的水平滚动。
<div style="margin-top:52px;" *ngFor="let chapter of chapters; let i = index" >
<li style="display: inline-block;float: left; padding: 0px 30px 0px 0px;"> chapter.name </li>
</div>
作为参考,在下面的例子中我们有带图片的电影名称。我只使用文本,
我当前的 ui 如下所示,我需要在点击事件滚动功能上实现它,
您正在寻找的是一个旋转木马...它具有您想要的滚动效果的箭头:
相关HTML:
<div class='containerDiv'>
<carousel [itemsPerSlide]="itemsPerSlide" [singleSlideOffset]="singleSlideOffset" [showIndicators]="false" [noWrap]="!noWrap"
[interval]="false" [startFromIndex]="0" (slideRangeChange)="onSlideRangeChange($event)">
<slide *ngFor="let slide of slides; let index=index">
<img [src]="slide.image" alt="image slide" style="display: block; width: 100%;">
<div class="carousel-caption">
<p>some optional text {{index}}</p>
</div>
</slide>
</carousel>
</div>
相关TS:
import { Component } from '@angular/core';
@Component({
selector: 'demo-carousel-multilist',
templateUrl: './multilist.html',
styles: [`
::ng-deep a.carousel-control-prev, a.carousel-control-prev:hover {left:-7% !important;}
::ng-deep .carousel-control-next, .carousel-control-next:hover {right:-8% !important;}
slide{margin:5px;}
.carousel-caption{position:relative; text-align: center; padding: 15px 0 0 0; bottom: 0;}
`]
})
export class DemoCarouselMultilistComponent {
itemsPerSlide = 4;
singleSlideOffset = false;
noWrap = false;
slidesChangeMessage = '';
slides = [
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/1.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/2.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/3.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/4.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/5.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/6.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/7.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/8.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/1.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/2.jpg'}
];
onSlideRangeChange(indexes: number[]): void {
this.slidesChangeMessage = `Slides have been switched: ${indexes}`;
}
}
我正在为 css 使用 Angular 6 和 bootstrap 框架。我想在单击 left/right 按钮时水平滚动 div。
我想滚动下面的内容 div,章节名称可能包含一章或多于 1 章,即 1-10 章。如何实现点击 let 和右箭头按钮时的水平滚动。
<div style="margin-top:52px;" *ngFor="let chapter of chapters; let i = index" >
<li style="display: inline-block;float: left; padding: 0px 30px 0px 0px;"> chapter.name </li>
</div>
作为参考,在下面的例子中我们有带图片的电影名称。我只使用文本,
我当前的 ui 如下所示,我需要在点击事件滚动功能上实现它,
您正在寻找的是一个旋转木马...它具有您想要的滚动效果的箭头:
相关HTML:
<div class='containerDiv'>
<carousel [itemsPerSlide]="itemsPerSlide" [singleSlideOffset]="singleSlideOffset" [showIndicators]="false" [noWrap]="!noWrap"
[interval]="false" [startFromIndex]="0" (slideRangeChange)="onSlideRangeChange($event)">
<slide *ngFor="let slide of slides; let index=index">
<img [src]="slide.image" alt="image slide" style="display: block; width: 100%;">
<div class="carousel-caption">
<p>some optional text {{index}}</p>
</div>
</slide>
</carousel>
</div>
相关TS:
import { Component } from '@angular/core';
@Component({
selector: 'demo-carousel-multilist',
templateUrl: './multilist.html',
styles: [`
::ng-deep a.carousel-control-prev, a.carousel-control-prev:hover {left:-7% !important;}
::ng-deep .carousel-control-next, .carousel-control-next:hover {right:-8% !important;}
slide{margin:5px;}
.carousel-caption{position:relative; text-align: center; padding: 15px 0 0 0; bottom: 0;}
`]
})
export class DemoCarouselMultilistComponent {
itemsPerSlide = 4;
singleSlideOffset = false;
noWrap = false;
slidesChangeMessage = '';
slides = [
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/1.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/2.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/3.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/4.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/5.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/6.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/7.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/8.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/1.jpg'},
{image: 'https://valor-software.com/ngx-bootstrap/assets/images/nature/2.jpg'}
];
onSlideRangeChange(indexes: number[]): void {
this.slidesChangeMessage = `Slides have been switched: ${indexes}`;
}
}