我需要在输入useEffect钩子时获得帮助,以便使Document.queryselector在代码底部工作.该脚本主要做的是获取数字和一个圆圈进度条,并将数字和圆圈进度条对齐,以同 timeshift 动它递增的每个数字.我只需要帮助添加useEffect挂钩,并使其工作时,页面刷新.:
import { SearchIcon } from "@heroicons/react/outline";
import { useState } from "react";
import News from "./News";
import { AnimatePresence, motion } from "framer-motion";
import dynamic from 'next/dynamic'
import {useEffect} from "react";
export default function Widgets({newsResults}) {
const[articleNum, setArticleNum] = useState(3);
return (
<div className="xl:w-[600px] lg:inline ml-8 space-y-5">
<div className="w-[90%] xl:w-[75%] sticky top-0 bg-white py-1.5 z-50">
<div className="flex items-center p-3 rounded-full bg-red-300 relative">
<SearchIcon className="h-5 z-50 text-gray-500 "/>
<input className="absolute inset-0 rounded-full pl-11 border-gray-500 text-gray-700 focus:shadow-lg focus:bg-white bg-gray-100" type="text" placeholder="Search RUbars" />
</div>
</div>
{/* <div className="text-gray-700 space-y-3 bg-gray-100 rounded-xl pt-2 w-[90%] xl:w-[75%]">
<h4 className="font-bold text-xl px-4">Whats happening</h4>
<AnimatePresence>
{newsResults.slice(0,articleNum).map((article)=>(
<motion.div key={article.title} initial={{opacity: 0 }} animate={{opacity: 1}} exit={{opacity: 0}} transition={{duration: 1}}>
<News key={article.title} article={article}/>
</motion.div>
))}
</AnimatePresence>
<button onClick={()=>setArticleNum(articleNum + 3)} className="text-rose-300 pl-4 pb-3 hover:text-rose-400">Show more</button>
</div> */}
<div className="text-gray-700 space-y-3 bg-gray-100 pt-2 rounded-xl w-[90%] xl:w-[75%]">
<h4 className="font-bold text-xl px-4">Capacity</h4>
<div class="container">
<div class="circular-progress">
<span class="progress-value">0%</span>
</div>
<span className="text">Olde Queens</span>
<div class="circular-progress">
<span className="progress-value">0%</span>
</div>
<span className="text1">Golden Rail</span>
<div class="circular-progress1">
<span className="progress-value1">0%</span>
</div>
<span className="text">Huey's Knight Club</span>
<button className="text-rose-300 pl-4 pb-3 hover:text-rose-400">Show more</button>
</div>
</div>
</div>
)
}
let circularProgress = document.querySelector(".circular-progress"),
progressValue = document.querySelector(".progress-value");
let progressStartValue = 0,
progressEndValue = 24,
speed = 40;
let progress = setInterval(() =>{
progressStartValue++;
progressValue.textContent = `${progressStartValue}%`
circularProgress.style.background = `conic-gradient(#E0115F ${progressStartValue * 3.6}deg, #ededed 0deg)`
if(progressStartValue == progressEndValue){
clearInterval(progress);
}
console.log(progressStartValue);
}, speed);
我知道它必须看起来像这样:
useEffect(() => {
let circularProgress = document.querySelector(".circular-progress");
console.log(circularProgress)
}, []);
但我真的不确定如何将其插入底部.