Dark Room Shadow Clock in HTML

ANSHPREET
By -
0


Greetings, budding web developers! Today, let's explore  HTML and CSS together for this amazing neon clock clock code. Fear not, dearbeginners; I'll break down each step, explaining not just what we're doing but also why we're doing it.


 Step 1: Setting Up the HTML Document


Open your text editor and create a new HTML file named `index.html`. In this file, we set the document structure.






Explanation:

- `<!DOCTYPE html>` declares the document type and version.

- `<html lang="en">` sets the language to English.

- The `<head>` section contains metadata, including character set, viewport settings, and your page title.

- `<link>` tags bring in external resources, like fonts and stylesheets.


 Step 2: Resetting Styles with CSS


Within the `<style>` tags, we're performing a style reset. Let's understand the key parts.


css




Explanation:

- `*`, `*::before`, and `*::after` selects all elements, including their pseudo-elements.

- `box-sizing: border-box;` makes sure padding and border are included in the element's total width and height.

- `font-family: 'Nunito Sans', sans-serif;` sets the default font.

- `font-size: 62.5%;` makes it easier to work with rem units (1.6rem = 16px).


 Step 3: HTML Structure


Now, let's go into the `<body>` of your page.


```html



```


Explanation:

- `<div class="wrapper">` creates a container to hold your content.

- `<main>` is a semantic HTML5 tag for the main content of your page.


 Step 4: Javascript Inclusion


Lastly, just before closing `</body>`, we include your JavaScript file.


```html

<script src="./script.js"></script>

</body>

</html>

```


Explanation:

- `<script>` includes external JavaScript files.


That's it! You've set up a foundation for your webpage. Now, as you add content inside `<main>`, refer to your CSS for styling.Let's Go fo CSS 🚀




CSS









Certainly! I'll provide an explanation for each section of the CSS code you provided side by side.


```css
html {
  font-size: 0.75vmin;
}
```
This sets the base font size for the HTML document to 0.75 times the viewport's minimum height or width, whichever is smaller. It helps in creating a responsive design.
```css
body {
  background-image: linear-gradient(to bottom, #131313, #000);
  perspective: 45rem;
  transform-style: preserve-3d;
}
```
This styles the `body` element. It sets a background image with a linear gradient from dark gray (#131313) to black (#000). The `perspective` property adds depth to 3D transformed elements within the body, and `transform-style: preserve-3d;` preserves the 3D transformations.
```css
.wrapper {
  -webkit-animation: camera-rotate 40s ease-in-out forwards infinite;
  animation: camera-rotate 40s ease-in-out forwards infinite;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}
```
This defines a wrapper element with animations. It rotates the camera continuously using the `camera-rotate` animation. The wrapper takes the full width and height of its parent, and `transform-style: preserve-3d;` ensures 3D transformations are preserved.
```css
main {
  /* ... (omitted for brevity) */
}
```
This styles the `main` element, which contains the main content. The `display: flex;` property makes its children flex items. The color of the text is set to a hue-saturation-lightness (HSL) value with varying lightness.
```css
main .digits {
  /* ... (omitted for brevity) */
}
```
This styles a class called `digits` within the `main` element. It contains styling for displaying digits using 3D transformations.
```css
main .colon-group {
  transform-style: preserve-3d;
}
```
This styles a class called `colon-group` within the `main` element. It ensures that 3D transformations are preserved for the colon group.
```css
main .shadow {
  top: 0;
  position: absolute;
  transform-origin: bottom center;
  transform: translateY(1rem) translateZ(2rem) rotateX(-90.1deg);
}
```
This styles a class called `shadow` within the `main` element. It positions the shadow element at the top with absolute positioning. The `transform` property applies translation, rotation, and perspective transformations.
```css
@-webkit-keyframes camera-rotate {
  /* ... (omitted for brevity) */
}
@keyframes camera-rotate {
  /* ... (omitted for brevity) */
}
```
These are keyframe animations (`@keyframes`). They define the `camera-rotate` animation that rotates the camera continuously. Both `-webkit-keyframes` and `keyframes` are used for compatibility with different browsers.
```css
@-webkit-keyframes camera-pan {
  /* ... (omitted for brevity) */
}
@keyframes camera-pan {
  /* ... (omitted for brevity) */
}
```
These are keyframe animations (`@keyframes`) defining the `camera-pan` animation that simulates a panning effect.
```css
@-webkit-keyframes hue-rotate {
  /* ... (omitted for brevity) */
}
@keyframes hue-rotate {
  /* ... (omitted for brevity) */
}
```
These are keyframe animations (`@keyframes`) defining the `hue-rotate` animation, which changes the color hue over time.
```css
.safari .digit span {
  transition: none !important;
}
```
This targets elements with class `digit` within elements with class `safari`. It disables transitions using `transition: none !important;`, particularly for Safari browsers.
```css
.safari .digit span::before {
  /* ... (omitted for brevity) */
}
```
This targets pseudo-elements `::before` within elements with class `digit` within elements with class `safari`. It further styles the `::before` pseudo-elements.


Click to copy code
















SCRIPT










Certainly! Let's break down the provided JavaScript code step by step, explaining each line in a beginner-friendly way:

```javascript
const bars = [
['end', 'top'],
['side', 'top', 'left'],
['side', 'top', 'right'],
['middle'],
['side', 'bottom', 'left'],
['side', 'bottom', 'right'],
['end', 'bottom']
];
```
This creates a constant array named `bars`, which represents the different parts (bars) that make up a digit. Each element in the array is an array of classes, describing the position of bars for each digit.

```javascript
const $main = document.querySelector('main');
```
This selects the HTML element with the tag name 'main' and assigns it to the variable `$main`. It assumes there is an HTML `<main>` element in the document.

```javascript
const addDigits = number => {
// ...
}
```
This defines a function `addDigits` that takes a `number` as a parameter. Inside this function, a series of elements representing digits and their bars are created based on the provided `bars` array.

```javascript
const initGroup = (number, padding = 2) => {
// ...
}
```
This function initializes a group of digits. It creates HTML elements for a group, individual digits, and bars. It allows for a variable amount of padding, defaulting to 2.

```javascript
const $digits = document.createElement('div');
$digits.classList.add('digits');
```
This creates a new `<div>` element and assigns it to the variable `$digits`. It also adds the class 'digits' to this new element.

```javascript
const group = initGroup(number);
const groupShadow1 = initGroup(number);
const groupShadow2 = initGroup(number);
```
These lines create three groups of digits (original and two shadows) using the `initGroup` function.

```javascript
$digits.append(group.element);
$digits.append(groupShadow1.element);
$digits.append(groupShadow2.element);
```
These lines append the original digit group and its shadow groups to the `$digits` container.

```javascript
$main.append($digits);
```
This appends the `$digits` container to the main HTML element.

```javascript
return {
// ...
}
```
This returns an object with methods for setting and getting the number value for the digit groups.

```javascript
const addColon = () => {
// ...
}
```
This defines a function `addColon` that creates HTML elements for displaying colons between digits.

```javascript
const $colonGroup = document.createElement('div');
$colonGroup.classList.add('colon-group');
```
This creates a new `<div>` element for the colon and adds the class 'colon-group' to it.

```javascript
const $colon = document.createElement('figure');
$colon.append(document.createElement('span'));
```
This creates a `<figure>` element for the colon and appends a `<span>` element to it.

```javascript
$colonGroup.append($colon);
$main.append($colonGroup);
```
These lines append the colon group to the main HTML element.

```javascript
const init = () => {
// ...
}
```
This defines a function `init` that initializes the clock by creating digit groups for hours, minutes, and seconds, and continuously updates them.

```javascript
if (/^(?:(?!chrome|android)[\s\S])*(?:safari|iPad|iPhone|iPod)/i.test(navigator.userAgent)) {
document.body.classList.add('safari');
}
```
This checks if the user is using Safari by examining the user agent string. If true, it adds the class 'safari' to the `<body>` element.

```javascript
init();
```
This calls the `init` function to start the clock.

I hope this breakdown helps you understand each part of the JavaScript code! If you have further questions, feel free to ask.












Tags:

Post a Comment

0Comments

Post a Comment (0)
Loading {title}...