所以,我试图用 Flickity 和 React 制作一个这样的画廊,但我得到了一些奇怪的闪烁,并且动画不会开始,直到我尝试调整(输出)窗口的大小,然后一切都很好。在 Firefox 上,有时有效,有时无效,而 Chrome 拒绝完全合作。也许值得一提的是,我使用纯 Javascript 和 Flickity 完成了这项工作,所以我想我在 React 中做错了什么。这是代码:
HTML:
<div id="main"></div>
反应JS
var Gallery = React.createClass({
componentDidMount: function() {
this.flkty = new Flickity('.gallery', {
freeScroll: true,
wrapAround: true,
prevNextButtons: false,
pageDots: false,
freeScrollFriction: 0.00,
lazyLoad: 2
});
this.flkty.velocity = 1;
this.flkty.isFreeScrolling = true;
this.flkty.startAnimation();
},
render: function() {
return (
<div className="gallery">
<div key="01" className="gallery-cell">
<img src="http://placehold.it/450x1500" />
</div>
<div key="02" className="gallery-cell">
<img src="http://placehold.it/850x1200" />
</div>
<div key="03" className="gallery-cell">
<img src="http://placehold.it/150x1500" />
</div>
<div key="04" className="gallery-cell">
<img src="http://placehold.it/1850x1500" />
</div>
<div key="05" className="gallery-cell">
<img src="http://placehold.it/650x1000" />
</div>
<div key="06" className="gallery-cell">
<img src="http://placehold.it/350x2500" />
</div>
</div>
)}
});
ReactDOM.render(
<Gallery />,
document.getElementById('main')
);
社会保障体系:
html,
body {
height: 100%;
margin: 0;
padding: 0;
background: #833;
}
div#main {
margin: 0 auto;
width: 750px;
height: auto !important;
height: 100%;
min-height: 100%;
}
.gallery {
background: #EEE;
overflow: hidden;
}
.gallery-cell {
display: inline-block;
height: 100vh;
img {
border-left: 2px solid #444;
height: 100%;
}
}