Home Web Front-end JS Tutorial I Built the ULTIMATE Educational Website from Scratch — Day 5

I Built the ULTIMATE Educational Website from Scratch — Day 5

Jan 15, 2025 am 11:08 AM

I Built the ULTIMATE Educational Website from Scratch — Day 5

Yesterday, we worked on Periodic Properties, a specific article. Today, let's focus back on the actual site design and pages.

We'll create the organic chemistry page. We'll start by setting up the basic HTML structure, including placeholders for the interactive elements.

Hour 23: Building the Organic Chemistry Page

First, I created organic.html inside the Chemistry folder. This is the basic structure:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Neuron IQ - Organic Chemistry</title>

    <meta name="description" content="Explore the fascinating world of organic chemistry with interactive articles, quizzes, and 3D molecule visualizations.">

 

    <link rel="preconnect" href="https://fonts.googleapis.com">

    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap" rel="stylesheet">

 

    <!-- Favicon -->

    <link rel="icon" type="image/png" href="/favicon.png">

 

    <!-- Stylesheets (Consider using a CSS preprocessor like Sass for better organization) -->

    <link rel="stylesheet" href="css/style-main.css">

    <link rel="stylesheet" href="css/style.css">

    <link rel="stylesheet" href="css/specific-chemistry.css">

</head>

<body>

    <header>

        <nav>

            <div>

 

 

 

<p>I've added basic structure, links to the main stylesheets, and CDN link to a 3D molecule viewer library molGL. I've also added a basic header and footer, consistent with our previous pages, and a button for hamburger menu.</p>

 

<p>Now, I'll add the main content area, divided into sections for articles, key topics, and an interactive molecule viewer.<br>

</p>

 

<pre class="brush:php;toolbar:false"><section>

 

 

 

<p>This code adds a three-column layout. The left column will house the article list with a search bar. The middle column will have a hero section with a call-to-action button and a grid of topic cards with images. Finally, the right column will feature the interactive 3D molecule viewer.</p>

 

<p>I've also added placeholders for images within the topic cards (images/hydrocarbons.jpg, etc.). We'll need to replace these with actual images later.</p>

 

<h2>

   

   

  Hour 24: Adding JavaScript for Interactivity

</h2>

 

<p>Now, let's add some basic JavaScript to handle the hamburger menu, the article search functionality, and the 3D molecule viewer. I'll add the following inside the <script> tag at the end of the body:<br>

 

 

<pre class="brush:php;toolbar:false">        // Hamburger Menu Toggle

const hamburgerBtn = document.getElementById('hamburger-btn');

const navMenu = document.getElementById('nav-menu');

 

hamburgerBtn.addEventListener('click', () => {

  navMenu.classList.toggle('show');

});

 

// Article Search Functionality (Basic Example)

const articleSearch = document.getElementById('article-search');

const articleLinks = document.getElementById('article-links').querySelectorAll('a');

 

articleSearch.addEventListener('input', () => {

  const searchTerm = articleSearch.value.toLowerCase();

 

  articleLinks.forEach(link => {

    const linkText = link.textContent.toLowerCase();

    if (linkText.includes(searchTerm)) {

      link.style.display = 'block';

    } else {

      link.style.display = 'none';

    }

  });

});

 

// 3D Molecule Viewer (MolGL Example)

const molContainer = document.getElementById('mol-container');

const moleculeSelect = document.getElementById('molecule-select');

 

// Initialize MolGL viewer

let viewer = new MolGL({

  container: molContainer,

  style: {

    stick: {},

    sphere: { scale: 0.3 }

  }

});

 

// Load a default molecule

viewer.load('pdb:1crn'); // Example: Load a PDB structure

 

// Change molecule on selection

moleculeSelect.addEventListener('change', () => {

  const selectedMolecule = moleculeSelect.value;

  // We'll need to map molecule names to appropriate data sources (e.g., PDB IDs, SDF files)

  if (selectedMolecule === 'methane') {

    viewer.load('sdf:./molecules/methane.sdf'); // Example: Load from an SDF file

  } else if (selectedMolecule === 'ethanol') {

    viewer.load('pdb:1etn');

  } else if (selectedMolecule === 'benzene') {

    viewer.load('sdf:./molecules/benzene.sdf');

  }

});

Copy after login

Here's what this JavaScript does:

  1. Hamburger Menu Toggle: Adds an event listener to the hamburger button to toggle the show class on the navigation menu, making it visible or hidden on small screens.
  2. Article Search: Implements a simple search functionality that filters the article links based on the user's input in the search bar.
  3. 3D Molecule Viewer:
    • Initializes a MolGL viewer instance within the mol-container element.
    • Loads a default molecule (crambin protein, 1crn) in PDB format from external link.
    • Adds an event listener to the molecule selection dropdown to load different molecules when the user makes a selection.
    • Uses placeholder molecule data sources (./molecules/methane.sdf, etc.). We'll need to provide actual molecule data in the correct format (SDF, PDB, etc.) and map the molecule names accordingly.

Live page is over here, if you want to see:

Organic Chemistry - NeuronIQ

Hour 25: Creating the Inorganic Chemistry Page

Let's create a new page for inorganic chemistry, similar in structure to the organic chemistry page.

First, I created inorganic.html inside the Chemistry folder with the following basic structure:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Neuron IQ - Inorganic Chemistry</title>

    <link rel="stylesheet" href="style.css">

       <link rel="preconnect" href="https://fonts.googleapis.com">

    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap" rel="stylesheet">

     <link rel="stylesheet" href="style-main.css">

      <link rel="stylesheet" href="specific-chemistry.css">

</head>

<body>

    <header>

        <nav>

            <div>

 

 

 

<p>This code sets up the HTML for the page with:</p>

 

<ul>

<li>  A basic header with navigation links.</li>

<li>  An aside element for the article list.</li>

<li>  A main content area with a heading, introductory text, and a grid for key topics.</li>

<li>  Placeholder links for articles and topics.</li>

<li>  A footer.</li>

</ul>

 

<p>We are using style.css, style-main.css and specific-chemistry.css for the styling.</p>

 

<p>Next, I added some content to the page:<br>

</p>

 

<pre class="brush:php;toolbar:false"><section>

 

 

 

<p>I also added a search bar and some links, that we will add later.</p>

 

<h2>

   

   

  Hour 26: Adding JavaScript for Search Functionality

</h2>

 

<p>Since we used a similar structure to the organic chemistry page, I copied over the JavaScript code for the hamburger menu and the article search functionality from organic.html to this inorganic chemistry page, removing the 3D molecule viewer part.<br>

</p>

 

<pre class="brush:php;toolbar:false">// Hamburger Menu Toggle

const hamburgerBtn = document.getElementById('hamburger-btn');

const navMenu = document.getElementById('nav-menu');

 

hamburgerBtn.addEventListener('click', () => {

  navMenu.classList.toggle('show');

});

 

// Article Search Functionality (Basic Example)

const articleSearch = document.getElementById('article-search');

const articleLinks = document.getElementById('article-links').querySelectorAll('a');

 

articleSearch.addEventListener('input', () => {

  const searchTerm = articleSearch.value.toLowerCase();

 

  articleLinks.forEach(link => {

    const linkText = link.textContent.toLowerCase();

    if (linkText.includes(searchTerm)) {

      link.style.display = 'block';

    } else {

      link.style.display = 'none';

    }

  });

});

Copy after login

I had to adjust the selectors to match the IDs used in this page. This script now handles the basic hamburger menu toggle and article search filtering.

We now have a basic inorganic.html page with a similar structure to the organic chemistry page. We can further enhance it by:

  1. Adding Content:
    • Write the actual articles for the topics listed.
    • Add images or diagrams to the topic grid.
  2. Styling:
    • Improve the visual presentation with CSS.
    • Ensure responsiveness for different screen sizes.
  3. More Interactivity:
    • Add quizzes or interactive diagrams as needed.
  4. Navigation:
    • Implement a more robust navigation system if the site becomes more complex, as the current one is quite basic

Since our main focus for today was setting up the structure and basic functionality, we can consider these enhancements in the next steps. We can also improve on this by adding more relevant content, and working on the responsiveness of the page.

The above is the detailed content of I Built the ULTIMATE Educational Website from Scratch — Day 5. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1258
29
C# Tutorial
1232
24
Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript: Exploring the Versatility of a Web Language JavaScript: Exploring the Versatility of a Web Language Apr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

From C/C   to JavaScript: How It All Works From C/C to JavaScript: How It All Works Apr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles