Endless visual possibilities and converting three-dimensional content with the help of HTML, CSS, JavaScript, and Bootstrap

Can you assist me in creating infinite images and implementing a 3D translation similar to this link [https://public.work/]

I am using HTML, CSS, JS, and Bootstrap 5

Your feedback would be highly appreciated. If there are alternative methods to achieve the same result, please do suggest them to me :)

I expect the output to resemble the one at [https://public.work/]

Here is my code: HTML:

<main>
  <div class="container-fluid">
    <div class="row">
      <div class="col-4 col-xl-3">
        <a href="pages/rib/products/blackShirt.html"
          ><img
            src="assets/images/rib/BLACK-SHIRT.jpg"
            class="img-fluid"
            alt="black-shirt"
        /></a>
      </div>
      ...
    </div>
  </div>
</main>

CSS:

  main {
  width: 100vw;
  height: 100vh;
  overflow: auto;
}

.container-fluid {
  width: 150%;
  height: 100%;
}

.img-fluid:hover {
  cursor: pointer;
}

@media (max-width: 576px) {
  .container-fluid {
    width: 200%;
    height: 200%;
  }
}

JS:

 document.addEventListener("DOMContentLoaded", (event) => {
  const images = document.querySelectorAll("main .img-fluid");

  images.forEach((img) => {
    img.style.cursor = "pointer";
    img.addEventListener("mousedown", (e) => {
      img.style.cursor = "grabbing";
      const shiftX = e.clientX - img.getBoundingClientRect().left;
      const shiftY = e.clientY - img.getBoundingClientRect().top;

      const moveAt = (pageX, pageY) => {
        img.style.left = pageX - shiftX + "px";
        img.style.top = pageY - shiftY + "px";
      };

      ...
    });

    img.ondragstart = () => {
      return false;
    };
  });
});

Answer №1

In this configuration, a seamless scroll effect will be generated where placeholder images are loaded dynamically as the user scrolls through the page. You can adjust the limit variable to control the number of images loaded per scroll. It is assumed that you have prior knowledge of promises and timeouts.

document.addEventListener("DOMContentLoaded", () => {
  const imageContainer = document.getElementById("image-container");
  const loading = document.getElementById("loading");

  let page = 1;
  const limit = 10; // Number of images to load per request

  const fetchImages = () => {
    // Simulate an API request to fetch images
    return new Promise((resolve) => {
      setTimeout(() => {
        const images = [];
        for (let i = 0; i < limit; i++) {
          images.push(
            `https://via.placeholder.com/600x200?text=Image+${
              (page - 1) * limit + i + 1
            }`
          );
        }
        resolve(images);
      }, 1000); // Simulate network delay
    });
  };

  const loadImages = async() => {
    loading.style.display = "block";
    const images = await fetchImages();
    loading.style.display = "none;

    images.forEach((src) => {
      const img = document.createElement("img");
      img.src = src;
      img.alt = "Placeholder Image";
      img.classList.add("image");
      imageContainer.appendChild(img);
    });

    page++;
  };

  const handleScroll = () => {
    const scrollTop = window.scrollY;
    const windowHeight = window.innerHeight;
    const documentHeight = document.documentElement.scrollHeight;

    if (scrollTop + windowHeight >= documentHeight - 10) {
      loadImages();
    }
  };

  // Initial load
  loadImages();

  // Attach scroll event listener
  window.addEventListener("scroll", handleScroll);
});
body {
  font-family: Arial, sans-serif;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
  padding: 20px;
}

.image {
  width: 100%;
  max-width: 600px;
  height: 200px;
  margin-bottom: 20px;
  background: lightgrey;
}

.loading {
  text-align: center;
  margin: 20px 0;
}
<div class="container" id="image-container">
  <!-- Images will be appended here -->
</div>
<div class="loading" id="loading">Loading...</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Refresh the value of a JavaScript variable on the server using a script executed on the client side

Hello, I'm working on a webpage that utilizes JavaScript to find the location of my device. I am interested in updating the variables within the JavaScript code from a script that runs on my laptop. Is this even possible? Below is the code snippet: i ...

Transitioning opacity and visibility in iOS CSS styling

Check out this test on a desktop browser by visiting the following link (JSFiddle): a { background: gray; display: block; margin: 100px; padding: 100px; } a span { opacity: 0; -webkit-transition: 0.5s; visibility: hidden; } a:hover span { ...

Adjust the size of the HTML input font to decrease as additional text is entered

Is it possible to create an HTML text field that automatically adjusts the font size when the user types more characters than it can display? I know Acrobat has this feature for forms, but I'm looking to implement it in HTML. So, imagine having a te ...

Monitoring every request in Express.js(logging)

My web application is built on node and express for the backend. With a large number of users, debugging using console logs can be confusing due to messy logs from different users. Is there a way to track logs based on requests (like a Request ID)? ...

Transforming a function into an array in TypeScript

I attempted to use the map() function on a dataURL array obtained from the usePersonList() hook, but I am struggling to convert my function to an array in order to avoid errors when clicking a button. import Axios from "axios"; import React, { us ...

Reference now inactive in an array object no longer exhibiting reactivity

After implementing the following code successfully, we noticed that changing the language updates the text correctly thanks to the ref: const mainNavigationLinks = computed(() => [ { label: context.root.$t('navigationMenu.home') }, { labe ...

When working with async functions in JavaScript using await, the second function may not necessarily wait for the first function to complete before executing again

My goal is to implement async await in Angular 10 for loading a list of users from the backend database (built with Spring Boot and MariaDB) using an http request, and then filtering that list for one specific user. However, I'm facing an issue where ...

Steer clear of encountering the "$digest already in progress" issue

A custom directive named 'myPagination' has been implemented, which encapsulates the functionality of the UI Bootstrap's pagination directive. angular.module('my-module') .directive('myPagination', ['$filter' ...

Automatic Addition of Row Numbers Enabled

I'm currently exploring coding and experimenting with creating a scorekeeper for family games. I've managed to add rows dynamically and automatically sum up the entered information in the "total" row at the bottom. However, I'm facing an iss ...

Personalize the appearance of the AWS Cognito sign-in page by adjusting the CSS settings in the cognitoConfig

I have been working on automating the creation of user pools in AWS Cognito. To accomplish this, I am utilizing a yaml file to configure all aspects of the process including user attributes and IDPs. However, I am facing some challenges when it comes to ...

What is the correct way to promise-ify a request?

The enchanting power of Bluebird promises meets the chaotic nature of request, a function masquerading as an object with methods. In this straightforward scenario, I find myself with a request instance equipped with cookies via a cookie jar (bypassing req ...

What causes the string to be treated as an object in React Native?

I am fetching a string value through an API and I need to display it in the View. However, the string value is coming as a Promise. How can I handle this? "Invariant Violation: Objects are not valid as a React child (found: object with keys {_40, _65 ...

"Exploring the world of two-dimensional arrays and enhancing user

My goal is to create a form that contains a list of products. When the user starts typing the product name, an autocomplete feature should display available options based on the product names (first array element). If the user selects a product, the pric ...

Tips for making your textbox more interactive

Having trouble with my suggestion box display in jQuery. When I add more textboxes, an error from autocomplete.php shows up. I'm new to scripts and need some guidance. Here is the HTML and JS for the suggestion box: < script type = "text/javascri ...

Show different JSON data based on the existence of another key in Javascript

Having recently started learning JavaScript, I attempted the code below but couldn't quite get it to work. Despite consulting various resources, I still wasn't successful. Desired Output: To check if AUTO damage is present in the data. If so, re ...

What is the best way to customize global styles in nextJS?

What's the best approach to override CSS rules from my global.css file for specific pages within my website? ...

VueJS with Vuetify: Issue with draggable cards in a responsive grid

I am currently working on creating a gallery that allows users to rearrange images. To test this functionality, I am using an array of numbers. It is important that the gallery is responsive and displays as a single column on mobile devices. The issue I ...

Combining Three HTML Tags Into a Single Page

I currently have a standard PHP webpage that consists of the header, body, and footer sections. Within this setup, I use the following code: <?php include('header.html'); ?> The header.html file contains <html>... content </html& ...

Using socket.io and express for real-time communication with WebSockets

I'm currently working on implementing socket.io with express and I utilized the express generator. However, I am facing an issue where I cannot see any logs in the console. Prior to writing this, I followed the highly upvoted solution provided by G ...

Tips on how to customize/ng-class within a directive containing a template using replace: true functionality

To keep replace: true, how can ng-class be implemented on the directive below without causing conflicts with the template's ng-class? This currently results in an Angular error: Error: Syntax Error: Token '{' is an unexpected token at co ...