我正在尝试将bulma carousel合并到我的反应应用程序中,但它似乎无法正常工作。我已经尝试使用Bulma Carousel这个文档实现它,但它似乎似乎不起作用。
这是我的代码,随意指出在哪里做正确的工作。
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css" />
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<link rel="stylesheet" href="./css/style.css" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Simple React App</title>
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="/node_modules/bulma-extensions/bulma-carousel/dist/js/bulma-carousel.min.js"></script>
<script>
window.onload = function () {
var carousels = bulmaCarousel.attach();
console.log(carousels);
}
</script>
</body>
</html>
这是我的Carousel组件:
import * as React from "react";
import { render } from "react-dom";
const Carousel = () => {
return (
<div>
<div className="carousel carousel-animated carousel-animate-slide">
<div className="carousel-container">
<div className="carousel-item has-background is-active">
<img
className="is-background"
src="https://wikiki.github.io/images/merry-christmas.jpg"
alt=""
width="640"
height="310"
/>
<div className="title">Merry Christmas</div>
</div>
<div className="carousel-item has-background">
<img
className="is-background"
src="https://wikiki.github.io/images/singer.jpg"
alt=""
width="640"
height="310"
/>
<div className="title">
Original Gift: Offer a song with{" "}
<a href="https://lasongbox.com" target="_blank">
La Song Box
</a>
</div>
</div>
<div className="carousel-item has-background">
<img
className="is-background"
src="https://wikiki.github.io/images/sushi.jpg"
alt=""
width="640"
height="310"
/>
<div className="title">Sushi time</div>
</div>
<div className="carousel-item has-background">
<img
className="is-background"
src="https://wikiki.github.io/images/life.jpg"
alt=""
width="640"
height="310"
/>
<div className="title">Life</div>
</div>
</div>
<div className="carousel-navigation is-overlay">
<div className="carousel-nav-left">
<i className="fa fa-chevron-left" aria-hidden="true" />
</div>
<div className="carousel-nav-right">
<i className="fa fa-chevron-right" aria-hidden="true" />
</div>
</div>
</div>
</div>
);
};
export default Carousel;
我还使用npm i bulma-extensions
在我的节点模块中安装了Bulma扩展
注意:我是React和Bulma的新手
所以我终于找到了让它运行的有趣方法。
似乎旋转木马似乎不适用于npm版本npm i bulma-extensions
中包含的js。
什么时候我试图从carousel extension上提到的方法之一的模块添加js文件,它似乎没有工作
但是,当我从CDN使用此标签时,它工作正常
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bulma-carousel.min.js"></script>