我有第二个旋转木马随着点击和拖动移动...但我想显示箭头让用户知道这是一个滑块...有没有办法用materialize显示它?或者我是否必须以其他方式制作?
答案 0 :(得分:7)
<div class="carousel carousel-slider center" data-indicators="true">
<div class="carousel-fixed-item center">
<a class="btn waves-effect white grey-text darken-text-2">button</a>
</div>
<div class="carousel-item red white-text" href="#one!">
<h2>First Panel</h2>
<p class="white-text">This is your first panel</p>
</div>
<div class="carousel-item amber white-text" href="#two!">
<h2>Second Panel</h2>
<p class="white-text">This is your second panel</p>
</div>
<div class="carousel-item green white-text" href="#three!">
<h2>Third Panel</h2>
<p class="white-text">This is your third panel</p>
</div>
<div class="carousel-item blue white-text" href="#four!">
<h2>Fourth Panel</h2>
<p class="white-text">This is your fourth panel</p>
</div>
</div>
的Javascript
$('.carousel.carousel-slider').carousel({fullWidth: true});
这样的事情?
来源:http://materializecss.com/carousel.html
使用按钮&lt; &GT; :https://codepen.io/Paco_Cervantes/pen/ZLxKpj?q=materialize+carousel&limit=all&type=type-pens
如果您需要上一个特定字词或编辑,请告诉我
答案 1 :(得分:1)
希望这会对某人有所帮助;)
当Materialize.js版本低于v0.100时,请尝试以下操作:
$('.moveNextCarousel').click(function(e){
e.preventDefault();
e.stopPropagation();
$('.carousel').carousel('next');
});
如果您的Materialize.js版本等于或高于v0.100,请尝试以下操作:
$('#carousel-right').on('touchstart', function (e) {
e.preventDefault();
e.stopPropagation();
$('#carouselFirst').carousel('next');
});
我的HTML结构:
<div id="carouselFirst" class="carousel carousel-slider">
<div class="carousel-fixed-item center clearfix">
<a id="carousel-prev" class="movePrevCarousel btn waves-effect left">button</a>
<a id="carousel-next" class="moveNextCarousel btn waves-effect right">button</a>
</div>
<div class="carousel-item red white-text" href="#one!">
<h2>First Panel</h2>
<p class="white-text">This is your first panel</p>
</div>
<div class="carousel-item amber white-text" href="#two!">
<h2>Second Panel</h2>
<p class="white-text">This is your second panel</p>
</div>
<div class="carousel-item green white-text" href="#three!">
<h2>Third Panel</h2>
<p class="white-text">This is your third panel</p>
</div>
<div class="carousel-item blue white-text" href="#four!">
<h2>Fourth Panel</h2>
<p class="white-text">This is your fourth panel</p>
</div>`enter code here`
</div>
我的Javascript:
$('.carousel.carousel-slider').carousel({
fullWidth: true,
indicators: false
});
$('#carousel-next').on('touchstart', function (e) {
e.preventDefault();
e.stopPropagation();
$('#carouselFirst').carousel('next');
});
$('#carousel-prev').on('touchstart', function (e) {
e.preventDefault();
e.stopPropagation();
$('#carouselFirst').carousel('prev');
});
答案 2 :(得分:0)
这是Angular的解决方案:
HTML:
<div id="carouselFirst" class="carousel carousel-slider">
<div class="carousel-fixed-item center clearfix">
<a (click)="prevSlide($event)" id="carousel-prev" class="movePrevCarousel carousel-arrow left">Previous</a>
<a (click)="nextSlide($event)" id="carousel-next" class="moveNextCarousel carousel-arrow right">Next</a>
</div>
<a *ngFor="let slide of slides" class="carousel-item" [href]="slide.href"><img [src]="slide.src"></a>
</div>
TypeScript:
declare var $: any;
export class SomethingComponent implements OnInit {
slides = [
{
id: 1,
href: '#one!',
src: '...'
},
.
.
.
];
prevSlide = (e) => {
e.preventDefault();
e.stopPropagation();
$('#carouselFirst').carousel('prev');
}
nextSlide = (e) => {
e.preventDefault();
e.stopPropagation();
$('#carouselFirst').carousel('next');
}
constructor() { }
ngOnInit() {
this.jquery_code();
}
jquery_code() {
$(document).ready(() => {
$('.carousel').carousel({
fullWidth: true,
indicators: true
});
});
}
答案 3 :(得分:0)
幻灯片后,创建以下div:
<div class="row slider-center"><i id="next" class="material-icons">chevron_right</i> <i id="prev" class="material-icons">chevron_left</i></div>
您的初始化:
<script>
$('.carousel').carousel({
fullWidth: true,
indicators: true
});
$('i#prev').click(function() {
$('.carousel').carousel('prev');
});
$('i#next').click(function() {
$('.carousel').carousel('next');
});
</script>
还有我们的CSS:
.row.slider-center {
position: absolute;
top:50%;
width:100%;
}
i#next {
position: absolute;
right: 10px;
color: #fff;
background: #634e4e99;
font-size: 35px;
font-weight: 800;
border-radius: 50px;
border: 1px solid;
}
i#prev {
position: absolute;
left: 20px;
color: #fff;
background: #634e4e99;
font-size: 35px;
font-weight: 800;
border-radius: 50px;
border: 1px solid;
}
应该可以。