|
@@ -50,32 +50,50 @@ function B1VillageM() {
|
|
// 详情 索引
|
|
// 详情 索引
|
|
const [infoInd, setInfoInd] = useState(-1);
|
|
const [infoInd, setInfoInd] = useState(-1);
|
|
|
|
|
|
|
|
+ // 序列帧dom
|
|
|
|
+ const moveWai = useRef<HTMLDivElement>(null);
|
|
|
|
+ const moveIn = useRef<HTMLImageElement>(null);
|
|
|
|
+
|
|
// 每次索引变化的时候 动态加载 序列帧样式
|
|
// 每次索引变化的时候 动态加载 序列帧样式
|
|
const setFullFu = useCallback(() => {
|
|
const setFullFu = useCallback(() => {
|
|
// 看看是否已经插入的 script
|
|
// 看看是否已经插入的 script
|
|
const ruDom = document.querySelector("#myStyle");
|
|
const ruDom = document.querySelector("#myStyle");
|
|
if (ruDom) ruDom.remove();
|
|
if (ruDom) ruDom.remove();
|
|
-
|
|
|
|
clearTimeout(time.current);
|
|
clearTimeout(time.current);
|
|
time.current = window.setTimeout(() => {
|
|
time.current = window.setTimeout(() => {
|
|
if (infoInd === -1) return;
|
|
if (infoInd === -1) return;
|
|
|
|
|
|
- const num = curVillage[infoInd].zhen;
|
|
|
|
- // 获取序列帧 外层 盒子的 宽度
|
|
|
|
- const dom = document.querySelector(".B1imgMove") as HTMLDivElement;
|
|
|
|
- if (dom) {
|
|
|
|
- const width = dom.getBoundingClientRect().width;
|
|
|
|
- const leftNum = "-" + width * num + "px";
|
|
|
|
|
|
+ if (moveIn.current && moveWai.current) {
|
|
|
|
+ // 配置的数据 帧数
|
|
|
|
+ const zhenNum = curVillage[infoInd].zhen;
|
|
|
|
+
|
|
|
|
+ // 配置的数据 帧动画的速度
|
|
|
|
+ const zhenSuDu = curVillage[infoInd].zhenSuDu;
|
|
|
|
+
|
|
|
|
+ // 图片的总宽度(自适应的宽度)
|
|
|
|
+ moveIn.current.style.width = "auto";
|
|
|
|
+ const imgWidth = moveIn.current.clientWidth;
|
|
|
|
+
|
|
|
|
+ // 设置外层盒子的宽度(取整)
|
|
|
|
+ const waiWdith = Math.round(imgWidth / zhenNum);
|
|
|
|
+ moveWai.current.style.width = waiWdith + "px";
|
|
|
|
+
|
|
|
|
+ // 重新设置图片的宽度(整数)
|
|
|
|
+ const lastInWdith = waiWdith * zhenNum;
|
|
|
|
+ moveIn.current.style.width = lastInWdith + "px";
|
|
|
|
+
|
|
|
|
+ // console.log(imgWidth, imgWidth / num);
|
|
|
|
+
|
|
const styleStr = `.B1VinfoAc .B1imgMoveMain {
|
|
const styleStr = `.B1VinfoAc .B1imgMoveMain {
|
|
- animation: tab2MoveImg 2.4s steps(${num}) infinite;
|
|
|
|
|
|
+ animation: tab2MoveImg ${(zhenNum / zhenSuDu).toFixed(
|
|
|
|
+ 1
|
|
|
|
+ )}s steps(${zhenNum}) infinite;
|
|
}
|
|
}
|
|
@keyframes tab2MoveImg {
|
|
@keyframes tab2MoveImg {
|
|
-
|
|
|
|
100% {
|
|
100% {
|
|
- left: ${leftNum};
|
|
|
|
|
|
+ left: -${lastInWdith}px;
|
|
}
|
|
}
|
|
}`;
|
|
}`;
|
|
-
|
|
|
|
const styletDom = document.createElement("style");
|
|
const styletDom = document.createElement("style");
|
|
styletDom.type = "text/css";
|
|
styletDom.type = "text/css";
|
|
styletDom.id = "myStyle";
|
|
styletDom.id = "myStyle";
|
|
@@ -143,38 +161,36 @@ function B1VillageM() {
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
) : null}
|
|
{/* 上面的 序列帧 和 左右箭头 */}
|
|
{/* 上面的 序列帧 和 左右箭头 */}
|
|
- <div className="B1imgMove">
|
|
|
|
|
|
+ <div className="B1imgMove" ref={infoInd === i ? moveWai : null}>
|
|
{/* 图片的序列帧 */}
|
|
{/* 图片的序列帧 */}
|
|
{uId ? (
|
|
{uId ? (
|
|
<img
|
|
<img
|
|
|
|
+ ref={infoInd === i ? moveIn : null}
|
|
className={classNames("B1imgMoveMain")}
|
|
className={classNames("B1imgMoveMain")}
|
|
- style={{
|
|
|
|
- width: v.zhen * 100 + "%",
|
|
|
|
- maxWidth: v.zhen * 100 + "%",
|
|
|
|
- }}
|
|
|
|
src={`${baseUrl}/B1Village/pc/${uId}/move${v.id}.png`}
|
|
src={`${baseUrl}/B1Village/pc/${uId}/move${v.id}.png`}
|
|
alt=""
|
|
alt=""
|
|
/>
|
|
/>
|
|
) : null}
|
|
) : null}
|
|
-
|
|
|
|
- {/* 左右箭头 */}
|
|
|
|
- <div
|
|
|
|
- onClick={() => setInfoInd(infoInd - 1)}
|
|
|
|
- className={classNames(
|
|
|
|
- "B1infoAr B1infoAr1",
|
|
|
|
- infoInd === 0 ? "B1infoArNone" : ""
|
|
|
|
- )}
|
|
|
|
- hidden={curVillage.length <= 1}
|
|
|
|
- ></div>
|
|
|
|
- <div
|
|
|
|
- onClick={() => setInfoInd(infoInd + 1)}
|
|
|
|
- className={classNames(
|
|
|
|
- "B1infoAr B1infoAr2",
|
|
|
|
- infoInd >= curVillage.length - 1 ? "B1infoArNone" : ""
|
|
|
|
- )}
|
|
|
|
- hidden={curVillage.length <= 1}
|
|
|
|
- ></div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
+
|
|
|
|
+ {/* 左右箭头 */}
|
|
|
|
+ <div
|
|
|
|
+ onClick={() => setInfoInd(infoInd - 1)}
|
|
|
|
+ className={classNames(
|
|
|
|
+ "B1infoAr B1infoAr1",
|
|
|
|
+ infoInd === 0 ? "B1infoArNone" : ""
|
|
|
|
+ )}
|
|
|
|
+ hidden={curVillage.length <= 1}
|
|
|
|
+ ></div>
|
|
|
|
+ <div
|
|
|
|
+ onClick={() => setInfoInd(infoInd + 1)}
|
|
|
|
+ className={classNames(
|
|
|
|
+ "B1infoAr B1infoAr2",
|
|
|
|
+ infoInd >= curVillage.length - 1 ? "B1infoArNone" : ""
|
|
|
|
+ )}
|
|
|
|
+ hidden={curVillage.length <= 1}
|
|
|
|
+ ></div>
|
|
|
|
+
|
|
{/* 下面的信息 */}
|
|
{/* 下面的信息 */}
|
|
<div className="B1infoTxt">
|
|
<div className="B1infoTxt">
|
|
{/* 场景和构件的选择 */}
|
|
{/* 场景和构件的选择 */}
|