<DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>What Time is It?</title><linkrel="stylesheet"href="style.css"></head><body><divclass="clock"><h1id="twelve">12</h1><divclass="clock-face"><divclass="hand hour-hand"></div><divclass="hand min-hand"></div><divclass="hand second-hand"></div></div><!-- update the question mark to the number 6 --><h1id="six">?</h1></div><script src="script.js"></script></body></html>
样式.css
html{background-size:cover;font-family:'helvetica neue';text-align:center;font-size:10px;}h1{color:#FFC312;text-shadow:2px2px4px#000000;}body{/*change the background color to a gradient of your choice*/background:linear-gradient(tobottomright,#47D457,#0F1CCD);margin:0;font-size:2rem;display:flex;flex:1;min-height:100vh;align-items:center;}.clock{width:50rem;height:50rem;border:20pxsolidwhite;border-radius:50%;margin:50pxauto;position:relative;padding:2rem;box-shadow:0004pxrgba(0,0,0,0.1),inset0003px#EFEFEF,inset0010pxblack,0010pxrgba(0,0,0,0.2);}.clock-face{position:relative;width:100%;height:100%;transform:translateY(-3px);/* account for the height of the clock hands */}.hand{width:50%;height:6px;background:lightgrey;position:absolute;top:30%;transform-origin:100%;transform:rotate(90deg);transition:all0.05s;transition-timing-function:cubic-bezier(0.1,2.7,0.58,1);box-shadow:0004pxrgba(0,0,0,0.1),inset0003px#EFEFEF,inset0010pxblack,0010pxrgba(0,0,0,0.2);}#six{margin-top:-150px;}
脚本.js
constsecondHand=document.querySelector('.second-hand');constminsHand=document.querySelector('.min-hand');consthourHand=document.querySelector('.hour-hand');functionsetDate(){constnow=newDate();constseconds=now.getSeconds();constsecondsDegrees=((seconds/60)*360)+90;secondHand.style.transform=`rotate(${secondsDegrees}deg)`;constmins=now.getMinutes();constminsDegrees=((mins/60)*360)+((seconds/60)*6)+90;minsHand.style.transform=`rotate(${minsDegrees}deg)`;consthour=now.getHours();// change seconds to hours on the line belowconsthourDegrees=((seconds/12)*360)+((mins/60)*30)+90;hourHand.style.transform=`rotate(${hourDegrees}deg)`;}setInterval(setDate,1000);setDate();
自动加载扩展
在项目根目录下创建一个文件夹,并在其中.devcontainer存储一个文件。您可以通过创建一个 来预定义特定的扩展程序,以便在有人打开 Codespace 时加载。在 中,您可以提供 VS Code 扩展程序 ID 的值。以下是我的 devcontainer.json 示例:devcontainer.jsondevcontainer.jsondevcontainer.json
{"$schema":"https://aka.ms/codetour-schema","title":"Fix The Broken Clock","steps":[{"file":"index.html","line":2,"description":"Hey! 👋 Welcome to the Fix The Broken Clock workshop. Something is very wrong with this clock, and we need your help to fix it. Use this tour to guide you through the app, and learn how to interact with its live coding environment. Try changing their text content and watch it take effect immediately!\n\nClick the `Next` link below to keep learning 👇"},{"file":"index.html","line":22,"description":"Our clock has a question mark instead of the number 6. Update the `<h1 id='six'>?</h1>` to render the number 6!"},{"file":"style.css","line":13,"description":"Great job at fixing the numbers over the clock. Check out background colors for the clock. Hover over the `<hex>` color to choose the background color of your choice."},{"file":"script.js","line":14,"description":"The hour hand is moving just as fast as the second hand. Let’s fix this by changing the word `seconds` on line 14 to `hours`."},{"file":"script.js","line":18,"description":"Mission complete! Thank you for completing this workshop."}]}
此代码之旅应类似于以下屏幕截图:
提交并推送更改
即使是最有经验的工程师也很难掌握版本控制,所以我并不指望新手开发者在研讨会期间编写 git 命令。幸运的是,Codespaces 和 VS Code 都提供了源代码控制 UI。我使用这个 UI 来帮助与会者暂存、提交和推送他们的更改。