|
@ -1,7 +1,7 @@ |
|
|
import React, { Component } from 'react'; |
|
|
import React, { Component } from 'react'; |
|
|
import './left.less'; |
|
|
import './left.less'; |
|
|
class ReactCarousel extends Component { |
|
|
class ReactCarousel extends Component { |
|
|
chunk(arr, size) { |
|
|
chunk (arr, size) { |
|
|
var arr1 = new Array(); |
|
|
var arr1 = new Array(); |
|
|
for (var i = 0; i < Math.ceil(arr.length / size); i++) { |
|
|
for (var i = 0; i < Math.ceil(arr.length / size); i++) { |
|
|
arr1[i] = new Array(); |
|
|
arr1[i] = new Array(); |
|
@ -12,13 +12,10 @@ class ReactCarousel extends Component { |
|
|
if (!((i % size == 0) && (i != 0))) { |
|
|
if (!((i % size == 0) && (i != 0))) { |
|
|
arr1[j][x] = arr[i]; |
|
|
arr1[j][x] = arr[i]; |
|
|
x++; |
|
|
x++; |
|
|
// console.log("j=" + j + " " + "x=" + x);
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
j++; |
|
|
j++; |
|
|
x = 0; |
|
|
x = 0; |
|
|
// console.log("else:" + "j=" + j + " " + "x=" + x);
|
|
|
|
|
|
arr1[j][x] = arr[i]; |
|
|
arr1[j][x] = arr[i]; |
|
|
// console.log(arr1);
|
|
|
|
|
|
x++; |
|
|
x++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -28,15 +25,18 @@ class ReactCarousel extends Component { |
|
|
constructor() { |
|
|
constructor() { |
|
|
super(); |
|
|
super(); |
|
|
this.state = { |
|
|
this.state = { |
|
|
shuzu: [{ name: "南昌县迎宾大道管制路段", images: "/assets/images/leadership/shiyantu.png" }, |
|
|
shuzu: [ |
|
|
{ name: "南昌县迎宾大道管制路段2", images: "/assets/images/leadership/shiyantu.png" }, |
|
|
{ name: '沙潭至五星', img: "/assets/images/leadership/fake/1.jpg" }, |
|
|
{ name: "南昌县迎宾大道管制路段3", images: "/assets/images/leadership/shiyantu.png" }, |
|
|
{ name: '滁槎至协城', img: "/assets/images/leadership/fake/2.jpg" }, |
|
|
{ name: "南昌县迎宾大道管制路段4", images: "/assets/images/leadership/shiyantu.png" }, |
|
|
{ name: '瓜山至广福', img: "/assets/images/leadership/fake/3.jpg" }, |
|
|
{ name: "南昌县迎宾大道管制路段", images: "/assets/images/leadership/shiyantu.png" }, |
|
|
{ name: '罗舍至泗洪', img: "/assets/images/leadership/fake/4.jpg" }, |
|
|
{ name: "南昌县迎宾大道管制路段", images: "/assets/images/leadership/shiyantu.png" }, |
|
|
{ name: '渔业至万州', img: "/assets/images/leadership/fake/5.jpg" }, |
|
|
{ name: "南昌县迎宾大道管制路段", images: "/assets/images/leadership/shiyantu.png" }, |
|
|
{ name: '沙潭至五星', img: "/assets/images/leadership/fake/1.jpg" }, |
|
|
{ name: "南昌县迎宾大道管制路段", images: "/assets/images/leadership/shiyantu.png" }, |
|
|
{ name: '滁槎至协城', img: "/assets/images/leadership/fake/2.jpg" }, |
|
|
{ name: "南昌县迎宾大道管制路段", images: "/assets/images/leadership/shiyantu.png" }], |
|
|
{ name: '瓜山至广福', img: "/assets/images/leadership/fake/3.jpg" }, |
|
|
|
|
|
{ name: '罗舍至泗洪', img: "/assets/images/leadership/fake/4.jpg" }, |
|
|
|
|
|
{ name: '渔业至万州', img: "/assets/images/leadership/fake/5.jpg" }, |
|
|
|
|
|
], |
|
|
imgs: [], |
|
|
imgs: [], |
|
|
showIndex: 0, //显示第几个图片
|
|
|
showIndex: 0, //显示第几个图片
|
|
|
timer: null, // 定时器
|
|
|
timer: null, // 定时器
|
|
@ -47,9 +47,7 @@ class ReactCarousel extends Component { |
|
|
this.state.imgs = this.chunk((this.state.shuzu), 4) |
|
|
this.state.imgs = this.chunk((this.state.shuzu), 4) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div className="ReactCarousel" style={{ width: "100%", height: "100%" }}> |
|
|
<div className="ReactCarousel" style={{ width: "100%", height: "100%" }}> |
|
|
<div className="contain" |
|
|
<div className="contain" |
|
@ -58,13 +56,12 @@ class ReactCarousel extends Component { |
|
|
> |
|
|
> |
|
|
<ul className="ul"> |
|
|
<ul className="ul"> |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
this.state.imgs.map((value, index) => { |
|
|
this.state.imgs.map((value, index) => { |
|
|
return ( |
|
|
return ( |
|
|
<li style={{ position: "relative", left: "8%", width: "100%", height: "100%", top: "-5%", fontSize: "12px" }} className={index === this.state.showIndex ? 'show' : ''} |
|
|
<li style={{ position: "relative", left: "8%", width: "100%", height: "100%", top: "-5%", fontSize: "12px" }} className={index === this.state.showIndex ? 'show' : ''} |
|
|
key={index} |
|
|
key={index} |
|
|
> |
|
|
> |
|
|
<div style={{ width: "45%", height: "40%", backgroundColor: "red", position: "absolute", left: "-3%", top: "5%" }}> |
|
|
<div style={{ width: "45%", height: "40%", backgroundImage: `url(${value[0].img})`, backgroundSize: 'cover', position: "absolute", left: "-3%", top: "5%" }}> |
|
|
<div style={{ width: "100%", height: "100%", position: "absolute", top: "80%" }}> |
|
|
<div style={{ width: "100%", height: "100%", position: "absolute", top: "80%" }}> |
|
|
<div style={{ width: "100%", height: "20%", backgroundColor: "rgba(0,0,0,0.6)", overflow: "hiddden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}> |
|
|
<div style={{ width: "100%", height: "20%", backgroundColor: "rgba(0,0,0,0.6)", overflow: "hiddden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}> |
|
|
<img src='/assets/images/leadership/weizhis.png' style={{ width: "6%", height: "80%", marginLeft: "3%", marginRight: "3%" }} /> |
|
|
<img src='/assets/images/leadership/weizhis.png' style={{ width: "6%", height: "80%", marginLeft: "3%", marginRight: "3%" }} /> |
|
@ -73,7 +70,7 @@ class ReactCarousel extends Component { |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
</div> |
|
|
</div> |
|
|
{value[1]?.name ? <div style={{ width: "45%", height: "40%", backgroundColor: "#fff", position: "absolute", left: "45%", top: "5%" }}> |
|
|
{value[1]?.name ? <div style={{ width: "45%", height: "40%", backgroundImage: `url(${value[1].img})`, backgroundSize: 'cover', position: "absolute", left: "45%", top: "5%" }}> |
|
|
<div style={{ width: "100%", height: "100%", position: "absolute", top: "80%" }}> |
|
|
<div style={{ width: "100%", height: "100%", position: "absolute", top: "80%" }}> |
|
|
<div style={{ width: "100%", height: "20%", backgroundColor: "rgba(0,0,0,0.6)", overflow: "hiddden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}> |
|
|
<div style={{ width: "100%", height: "20%", backgroundColor: "rgba(0,0,0,0.6)", overflow: "hiddden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}> |
|
|
<img src='/assets/images/leadership/weizhis.png' style={{ width: "6%", height: "80%", marginLeft: "3%", marginRight: "3%" }} /> |
|
|
<img src='/assets/images/leadership/weizhis.png' style={{ width: "6%", height: "80%", marginLeft: "3%", marginRight: "3%" }} /> |
|
@ -81,7 +78,7 @@ class ReactCarousel extends Component { |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> : ""} |
|
|
</div> : ""} |
|
|
{value[2]?.name ? <div style={{ width: "45%", height: "40%", backgroundColor: "bule", position: "absolute", left: "-3%", top: "49%" }}> |
|
|
{value[2]?.name ? <div style={{ width: "45%", height: "40%", backgroundImage: `url(${value[0].img})`, backgroundSize: 'cover', position: "absolute", left: "-3%", top: "49%" }}> |
|
|
<div style={{ width: "100%", height: "100%", position: "absolute", top: "80%" }}> |
|
|
<div style={{ width: "100%", height: "100%", position: "absolute", top: "80%" }}> |
|
|
<div style={{ width: "100%", height: "20%", backgroundColor: "rgba(0,0,0,0.6)", overflow: "hiddden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}> |
|
|
<div style={{ width: "100%", height: "20%", backgroundColor: "rgba(0,0,0,0.6)", overflow: "hiddden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}> |
|
|
<img src='/assets/images/leadership/weizhis.png' style={{ width: "6%", height: "80%", marginLeft: "3%", marginRight: "3%" }} /> |
|
|
<img src='/assets/images/leadership/weizhis.png' style={{ width: "6%", height: "80%", marginLeft: "3%", marginRight: "3%" }} /> |
|
@ -89,7 +86,7 @@ class ReactCarousel extends Component { |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> : ""} |
|
|
</div> : ""} |
|
|
{value[3]?.name ? <div style={{ width: "45%", height: "40%", backgroundColor: "pink", position: "absolute", left: "45%", top: "49%" }}> |
|
|
{value[3]?.name ? <div style={{ width: "45%", height: "40%", backgroundImage: `url(${value[3].img})`, backgroundSize: 'cover', position: "absolute", left: "45%", top: "49%" }}> |
|
|
<div style={{ width: "100%", height: "100%", position: "absolute", top: "80%" }}> |
|
|
<div style={{ width: "100%", height: "100%", position: "absolute", top: "80%" }}> |
|
|
<div style={{ width: "100%", height: "20%", backgroundColor: "rgba(0,0,0,0.6)", overflow: "hiddden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}> |
|
|
<div style={{ width: "100%", height: "20%", backgroundColor: "rgba(0,0,0,0.6)", overflow: "hiddden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}> |
|
|
<img src='/assets/images/leadership/weizhis.png' style={{ width: "6%", height: "80%", marginLeft: "3%", marginRight: "3%" }} /> |
|
|
<img src='/assets/images/leadership/weizhis.png' style={{ width: "6%", height: "80%", marginLeft: "3%", marginRight: "3%" }} /> |
|
@ -112,7 +109,8 @@ class ReactCarousel extends Component { |
|
|
<li key={index} |
|
|
<li key={index} |
|
|
className={index === this.state.showIndex ? 'active' : ''} |
|
|
className={index === this.state.showIndex ? 'active' : ''} |
|
|
onClick={() => { this.change(index) }}> |
|
|
onClick={() => { this.change(index) }}> |
|
|
</li>) |
|
|
</li> |
|
|
|
|
|
) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -129,11 +127,11 @@ class ReactCarousel extends Component { |
|
|
</div> |
|
|
</div> |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
componentDidMount() { //一开始自动播放
|
|
|
componentDidMount () { //一开始自动播放
|
|
|
this.start(); |
|
|
this.start(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
componentWillUnmount() { //销毁前清除定时器
|
|
|
componentWillUnmount () { //销毁前清除定时器
|
|
|
this.stop(); |
|
|
this.stop(); |
|
|
} |
|
|
} |
|
|
stop = () => { //暂停
|
|
|
stop = () => { //暂停
|
|
|