|
@@ -1,10 +1,69 @@
|
|
-import { FC } from "react";
|
|
|
|
|
|
+import { FC, useCallback, useEffect, useRef, useState } from "react";
|
|
import { useNavigate } from "react-router";
|
|
import { useNavigate } from "react-router";
|
|
import HoverImg from "./images/map-hover-min.png";
|
|
import HoverImg from "./images/map-hover-min.png";
|
|
|
|
+import CloseIcon from "./images/close.png";
|
|
import "./index.scss";
|
|
import "./index.scss";
|
|
|
|
|
|
const HomePage: FC = () => {
|
|
const HomePage: FC = () => {
|
|
const navigate = useNavigate();
|
|
const navigate = useNavigate();
|
|
|
|
+ const noticeBarRef = useRef<any>();
|
|
|
|
+ const contentRef = useRef<any>();
|
|
|
|
+ const time = useRef(0);
|
|
|
|
+ const timer = useRef<NodeJS.Timer>();
|
|
|
|
+ const [noticeVisible, setNoticeVisible] = useState(true);
|
|
|
|
+ const [contentWidth, setContentWidth] = useState(0);
|
|
|
|
+ const [contentStyle, setContentStyle] = useState({
|
|
|
|
+ transitionDuration: "0s",
|
|
|
|
+ transform: "translateX(0px)",
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const startAnimate = useCallback(() => {
|
|
|
|
+ setContentStyle({
|
|
|
|
+ transitionDuration: "0s",
|
|
|
|
+ transform: `translateX(${noticeBarRef.current.offsetWidth}px)`,
|
|
|
|
+ });
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ setContentStyle({
|
|
|
|
+ transitionDuration: `${time.current}s`,
|
|
|
|
+ transform: `translateX(-${contentWidth}px)`,
|
|
|
|
+ });
|
|
|
|
+ }, 50);
|
|
|
|
+ }, [contentWidth]);
|
|
|
|
+
|
|
|
|
+ const openCycle = useCallback(
|
|
|
|
+ (width: number) => {
|
|
|
|
+ time.current = width / 70;
|
|
|
|
+ startAnimate();
|
|
|
|
+ timer.current = setInterval(() => {
|
|
|
|
+ startAnimate();
|
|
|
|
+ }, time.current * 1000);
|
|
|
|
+ },
|
|
|
|
+ [startAnimate]
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ const initNotice = useCallback(() => {
|
|
|
|
+ const barWidth = noticeBarRef.current.offsetWidth;
|
|
|
|
+ const contentWidth = contentRef.current.offsetWidth;
|
|
|
|
+ if (contentWidth >= barWidth) {
|
|
|
|
+ setContentWidth(contentWidth);
|
|
|
|
+ setNoticeVisible(true);
|
|
|
|
+ openCycle(contentWidth);
|
|
|
|
+ }
|
|
|
|
+ }, [noticeBarRef, contentRef, openCycle]);
|
|
|
|
+
|
|
|
|
+ const closeNotice = () => {
|
|
|
|
+ setNoticeVisible(false);
|
|
|
|
+ clearInterval(timer.current);
|
|
|
|
+ timer.current = undefined;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ initNotice();
|
|
|
|
+
|
|
|
|
+ return () => {
|
|
|
|
+ closeNotice();
|
|
|
|
+ };
|
|
|
|
+ }, []);
|
|
|
|
|
|
return (
|
|
return (
|
|
<div className="home">
|
|
<div className="home">
|
|
@@ -15,6 +74,25 @@ const HomePage: FC = () => {
|
|
alt=""
|
|
alt=""
|
|
onClick={() => navigate("/scene")}
|
|
onClick={() => navigate("/scene")}
|
|
/>
|
|
/>
|
|
|
|
+
|
|
|
|
+ {noticeVisible && (
|
|
|
|
+ <div className="notice">
|
|
|
|
+ <div className="notice__content">
|
|
|
|
+ <span>注:</span>
|
|
|
|
+ <div ref={noticeBarRef}>
|
|
|
|
+ <p ref={contentRef} style={contentStyle}>
|
|
|
|
+ 本区位图仅对项目周边大致情况的效果进行展示,非实景图,也非严格意义的地图,不反映各部分之间的实际距离。本公司对区位图内容不提供任何承诺和保证,也不作为交付标准,最终均以政府部门核准的规划文件为准。
|
|
|
|
+ </p>
|
|
|
|
+ </div>
|
|
|
|
+ <img
|
|
|
|
+ alt=""
|
|
|
|
+ className="notice__content__close"
|
|
|
|
+ src={CloseIcon}
|
|
|
|
+ onClick={closeNotice}
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ )}
|
|
</div>
|
|
</div>
|
|
);
|
|
);
|
|
};
|
|
};
|