我使用NPM下载了Bulma-carousel。我已经尝试在各种论坛中搜索和查看其他答案,但没有结果。
我的index.html
<!DOCTYPE html>
<head>
<script src="https://cdn.jsdelivr.net/npm/bulma-carousel@4.0.4/dist/js/bulma-carousel.min.js"></script>
<link rel="stylesheet" href="bulma-carousel.min.css">
<!-- <script src="~bulma-carousel/dist/js/bulma-carousel.min.js"></script> -->
<title>GIS</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script>
$(document).ready(function(){
var carousels = bulmaCarousel.attach(); // carousels now contains an array of all Carousel instances
});
</script>
</body>
</html>
我的轮播组件文件
import React from 'react';
import bulmaCarousel from 'bulma-carousel';
class Pictures extends React.Component {
constructor(props) {
super(props);
var carousels = bulmaCarousel.attach('.carousel', {
slidesToScroll: 1,
slidesToShow: 3
});
}
render() {
return (
<div>
<div class='carousel carousel-animated carousel-animate-slide'>
<div class='carousel-container'>
<div class='carousel-item has-background is-active'>
<img class="is-background" src="" alt="" width="640" height="310" />
<div class="title">Merry Christmas</div>
</div>
<div class='carousel-item has-background'>
<img class="is-background" src="https://wikiki.github.io/images/singer.jpg" alt="" width="640" height="310" />
<div class="title">Original Gift: Offer a song with <a href="https://lasongbox.com" target="_blank">La Song Box</a></div>
</div>
<div class='carousel-item has-background'>
<img class="is-background" src="https://wikiki.github.io/images/sushi.jpg" alt="" width="640" height="310" />
<div class="title">Sushi time</div>
</div>
</div>
</div>
</div>
)
}
}
export default Pictures
通过其他组件,图片组件被导出到我的应用程序组件中。
我的页面看起来就像一堆图片堆叠在一起。我之前已经安装了 Bulma 框架,并成功使用了 Hero 和 columns 等类,所以这里没有问题。我没有下载 bulma-extension,因为我不需要全部扩展。我不确定该将 bulma-carousel js 放在哪里或如何使用它,所以我尝试将它们放在各处看看是否会改变,但没有
我还很新于 ReactJS,如果除了轮播图还有其他的问题,请见谅。