Scrolling multiple background images vertically within a div alongside text

Is there a more efficient way to create a vertical scroll like this without overcomplicating things? I feel like my approach is incorrect.

https://i.sstatic.net/CRfqW.gif

Currently, I have a div with a background image and the (1) / (2) / etc. positioned using negative values and higher z-index than the div, fixed on top.

I was considering adding a JS listener to each paragraph to change the background image when triggered. However, this method won't achieve the scrolling effect that I desire, leading me to believe that I may be approaching this problem incorrectly.

My ideal scenario would involve the images scrolling in sync with the paragraph, creating a natural appearance. But stacking multiple divs, applying masks, and toggling display settings on and off seems overly complex.

Answer №1

One possible approach:

The idea is to establish a window where the background images are visible...

To achieve this, create a fixed element with a z-index of around 10, followed by positioning your images at a z-index of 1 to place them behind the window. Then set the z-index of your text to 20 so that it appears on top.

Below is a basic code sample:

https://codepen.io/anon/pen/LzQrYa

Code:

<div class="container">

  <div class="cover top"></div>
  <div class="cover right"></div>
  <div class="cover bottom"></div>
  <div class="cover left"></div>
  <div class="bg-image one"></div>
  <div class="bg-image two"></div>
  <div class="bg-image three"></div>

  <p class="text one">Text 1</p>
  <p class="text two">Text 2</p>
  <p class="text three">Text 3</p>
</div>

CSS:

.container {
  position: relative;
  display: inline-block;
  width: 100%;
  float: left;
}
.container .cover {
  position: fixed;
  display: inline-block;
  background-color: #ffffff;
  z-index: 10;
}
.container .cover.top { 
  top: 0; left: 0; 
  width: 100%; 
  height: 120px;
}
.container .cover.right { 
  top: 0; right: 0; 
  width: 100px; 
  height: 100%;
}
.container .cover.bottom { 
  bottom: 0; left: 0; 
  width: 100%; 
  height: 120px;
}
.container .cover.left { 
  top: 0; left: 0; 
  width: 500px; 
  height: 100%;
}
.container .bg-image {
  position: relative;
  display: inline-block;
  width: 100%;
  height: 400px;
  float: left;
}
.container .bg-image.one { background-color: #cccccc; }
.container .bg-image.two { background-color: #8ec640; }
.container .bg-image.three { background-color: #ff00ff; }

.container .text {
  position: absolute;
  display: inline-block;
  font-size: 40px;
  color: #000000;
  z-index: 20;
}
.container .text.one {
  top: 40px;
  left: 50px;
}
.container .text.two {
  top: 500px;
  left: 50px;
}
.container .text.three {
  top: 940px;
  left: 50px;
}

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

When using PHP, JavaScript, and HTML, you can trigger an image upload immediately after choosing a file using the

I currently have a small form with two buttons - one for browsing and another for uploading an image. I feel that having two separate buttons for this purpose is unnecessary. Is there a way to combine the browse and upload functions into just one button? ...

When attempting to connect to http://localhost:8545/ using Web3.js, the network encountered an error with the message

I am currently working on setting up web3.js for a website in order to enable Ethereum authentication. However, I encountered the following error: web3-light.js:4327 OPTIONS http://localhost:8545/ net::ERR_CONNECTION_REFUSED HttpProvider.send @ web3- ...

Ensure that the header logo is in perfect alignment with the body of the

I am facing an issue with the alignment of my header logo on a webpage. The body of the page has white space on each side, and I want the header logo to be aligned on the left so that it starts vertically at the same point as the body regardless of the win ...

Unable to refresh JSON data in Datatables

Ensuring this operation is simple, I am following the documentation. An ajax call returns a dataset in JSON format. The table is cleared successfully, but even though data is returned according to the console statement, the table remains empty after the su ...

Chosen Dropdown selection - Retrieve/Receive information

One of the challenges I'm facing involves a dropdown list on my web form that contains various dates. My main query is: How can I retrieve data for the selected date from a MySQL database and present it to the user? Additionally, if the chosen date do ...

Can you explain the significance of `window.jqueryFoo = false;`?

I came across this code snippet within a React component: export default class pageWithModal extends React.Component { constructor(props) { super(props); window.jqueryFoo = false; this.state = { modal: false, value: '&apo ...

Postponed in JQUERY | AJAX

My requirement is to retrieve data using the "SetUnit()" function, which includes asynchronous AJAX services. I attempted to use Deferred as suggested in this link, but it did not work for my needs. Code...... Function function SetUnit(query) { var ...

Having trouble using the dollar sign with the replace method in Javascript

Text to be replaced: https://fw.adsafeprotected.com/rjss/bs.serving-sys.com/52023/7720220/BurstingPipe/adServer.bs?cn=rsb&c=28&pli=1234567890&PluID=0&w=300&h=600&ord=[timestamp]&ucm=true&ncu=$${CLICK_URL_ENC}$&adsafe_pr ...

Ways to incorporate values into a stack

I have a collection of numbers that are currently being displayed in a chart format. I am looking to sum these numbers and show the total value in a label. How can I achieve this? $(function ZoneClick() { $("[id*=rbtnZone]").click(function() { ...

The lengthy string is not breaking into separate lines as expected in Internet Explorer

My querystring is quite long http://terra.cic.local/web/index.cfm//pm/uebersicht?sucheAufgeklappt=was%2Cwie%2Cwohin%2Cwann%2Cwer&sucheVon=&sucheBis=&sucheIstErsteSeiteAnzahlProdukteErmitteln=false&sucheIDReiseart=26&sucheHotelart=1081& ...

Generating JSON data from a loop with refined outcomes

My goal is to iterate through JSON data and extract "time", "blocks" information, while filtering the "amounts" based on a specific variable named _miner. So far, I've successfully retrieved the name, time, and blocks data, but I'm struggling wi ...

What sets apart running Protractor with Selenium compared to running Protractor without Selenium?

After referring to the protractor resource on Github, I discovered that there is an option to execute Protractor tests without utilizing Selenium server by setting directConnect: true. What sets apart running Protractor tests with a Selenium server compa ...

When using Node.js with Mongoose, you will receive a single object value instead of multiple values in an array

data=[{ locId: '332wn', locadetails: [ { loc: 'ny', status: true }, { loc: 'ca', status: null ...

Distribution of data in K6 according to percentage

Is it possible to distribute data based on percentages in K6? For instance, can you demonstrate how to do this using a .csv file? ...

Spring MVC applications might experience slow loading times when loading RequireJS libraries

Recently, I integrated RequireJS into my Spring MVC application to manage dependencies for various libraries, including jQuery and jQuery UI. Although I have successfully implemented it, I am facing an issue whenever the page is loaded or refreshed. Initia ...

I'm facing an issue where I am only able to update the first record in the database using axios and Post

There seems to be a strange issue where only the first record in the database can be updated, even though all records can be retrieved without any problems. Here is the situation: https://i.sstatic.net/bK5aI.png To clarify further: Since names are unique, ...

Here is a new version: "AJAX button enables updating a single row in SQLite database through PHP."

My webpage features a table that shows values entered by a user, along with two buttons for removal and completion. The table is part of a layout with three tabs named Tab1, Tab2, and Tab3. Each tab contains its own table displaying information related to ...

Utilizing multiple API calls to initiate JSON data and seamlessly integrate it across the entire system

I am currently developing a project that utilizes Vue.js and Laravel for implementation. The project is focused on academia and consists of units, lessons, and activities, all interrelated. Each unit contains multiple lessons, and each lesson contains mult ...

Placing icons in a div at arbitrary positions using VueJS

I am looking to create a unique div where I can position multiple material design icons randomly. For example: Link to Example Image Previously, I achieved this using jQuery. Now, I want to achieve the same result using VueJS with material design icons ...

Comparing Inline SVG to CSS Background Sprite

As I work on developing multiple pages for my app (currently utilizing Angular on the front-end), I find myself including numerous logos. In an effort to maintain code readability, I have begun creating directives for each SVG logo by embedding the inline ...