简体   繁体   English

CSS 的某些部分在 GitHub 页面中不起作用

[英]Some part of CSS not working in GitHub pages

I hosted my website using github pages and i have set a 404.html error page where i set a countdown timer which will redirect to the homepage in 15 sec so for the countdown clock i make this little animation(Code below(Run the Code Snippet)).我使用 github 页面托管了我的网站,并设置了一个 404.html 错误页面,我在其中设置了一个倒计时计时器,它将在 15 秒内重定向到主页,因此对于倒计时时钟,我制作了这个小动画(下面的代码(运行代码片段) ))。

 const FULL_DASH_ARRAY = 283; const WARNING_THRESHOLD = 10; const ALERT_THRESHOLD = 5; const COLOR_CODES = { info: { color: "green" }, warning: { color: "orange", threshold: WARNING_THRESHOLD }, alert: { color: "red", threshold: ALERT_THRESHOLD } }; const TIME_LIMIT = 15; let timePassed = 0; let timeLeft = TIME_LIMIT; let timerInterval = null; let remainingPathColor = COLOR_CODES.info.color; document.getElementById("app").innerHTML = ` <div class="base-timer"> <svg class="base-timer__svg" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <g class="base-timer__circle"> <circle class="base-timer__path-elapsed" cx="50" cy="50" r="45"></circle> <path id="base-timer-path-remaining" stroke-dasharray="283" class="base-timer__path-remaining ${remainingPathColor}" d=" M 50, 50 m -45, 0 a 45,45 0 1,0 90,0 a 45,45 0 1,0 -90,0 " ></path> </g> </svg> <span id="base-timer-label" class="base-timer__label">${formatTime( timeLeft )}</span> </div> `; startTimer(); function onTimesUp() { clearInterval(timerInterval); } function startTimer() { timerInterval = setInterval(() => { timePassed = timePassed += 1; timeLeft = TIME_LIMIT - timePassed; document.getElementById("base-timer-label").innerHTML = formatTime( timeLeft ); setCircleDasharray(); setRemainingPathColor(timeLeft); if (timeLeft === 0) { onTimesUp(); } }, 1000); } function formatTime(time) { const minutes = Math.floor(time / 60); let seconds = time % 60; if (seconds < 10) { seconds = `0${seconds}`; } return `${minutes}:${seconds}`; } function setRemainingPathColor(timeLeft) { const { alert, warning, info } = COLOR_CODES; if (timeLeft <= alert.threshold) { document .getElementById("base-timer-path-remaining") .classList.remove(warning.color); document .getElementById("base-timer-path-remaining") .classList.add(alert.color); } else if (timeLeft <= warning.threshold) { document .getElementById("base-timer-path-remaining") .classList.remove(info.color); document .getElementById("base-timer-path-remaining") .classList.add(warning.color); } } function calculateTimeFraction() { const rawTimeFraction = timeLeft / TIME_LIMIT; return rawTimeFraction - (1 / TIME_LIMIT) * (1 - rawTimeFraction); } function setCircleDasharray() { const circleDasharray = `${( calculateTimeFraction() * FULL_DASH_ARRAY ).toFixed(0)} 283`; document .getElementById("base-timer-path-remaining") .setAttribute("stroke-dasharray", circleDasharray); }
 body { font-family: sans-serif; display: grid; height: 100vh; place-items: center; } .base-timer { position: relative; width: 300px; height: 300px; } .base-timer__svg { transform: scaleX(-1); } .base-timer__circle { fill: none; stroke: none; } .base-timer__path-elapsed { stroke-width: 7px; stroke: grey; } .base-timer__path-remaining { stroke-width: 7px; stroke-linecap: round; transform: rotate(90deg); transform-origin: center; transition: 1s linear all; fill-rule: nonzero; stroke: currentColor; } .base-timer__path-remaining.green { color: rgb(65, 184, 131); } .base-timer__path-remaining.orange { color: orange; } .base-timer__path-remaining.red { color: red; } .base-timer__label { position: absolute; width: 300px; height: 300px; top: 0; display: flex; align-items: center; justify-content: center; font-size: 48px; }
 <div id="app"></div>

I got this timer code from css tricks website so when i run it in my pc with visual studio code live server it works perfectly fine but after i upload it in github it doesn't shows that properly here is how it shows( https://www.rohittechzone.com/404.html ) :我从css 技巧网站获得了这个计时器代码,所以当我在我的电脑上使用 Visual Studio 代码实时服务器运行它时,它运行得非常好,但是在我将它上传到 github 后,它没有正确显示,这里是它的显示方式( https:/ /www.rohittechzone.com/404.html ): 只是一个巨大的黑圈

It shows this huge black circle but it worked in live server, I guessed there is some part in css which github pages cant compail but the other part of the css works(remaining part in my website):( Please help me fix it.它显示了这个巨大的黑色圆圈,但它在实时服务器中工作,我猜想 css 中的某些部分 github 页面无法编译,但 css 的另一部分有效(我网站中的其余部分):( 请帮我修复它。

Thanks!谢谢!

Works for me (firefox).为我工作(火狐)。 In general css is just served from Github (or any other server for that matter) and run in your browser - same with javascript.一般来说,css 只是从 Github(或任何其他服务器)提供并在您的浏览器中运行 - 与 javascript 相同。 Try to open it with the same browser you did the development.尝试使用与开发相同的浏览器打开它。 Or better try to open the development instance with the browser you are using for github或者最好尝试使用您用于 github 的浏览器打开开发实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM