What is the best way to control and manipulate this parallax effect?

Having trouble getting the icon dog to appear correctly in this parallax effect. I want the full body of the dog icon to be displayed over the section, but I'm having no luck so far. Please see my code below and let me know if there are any corrections needed. Thank you.

html, body {
  height: 100%;
}
body {
  background: #f6f6f6;
  margin: 0;
  padding: 0;
}
#content {
  position: relative;
}
.Parallax {
  position: relative;
  z-index: 2;
  overflow: hidden;
  width: 90%;
  padding: 5%;
  height: 600px;
}
.Parallax:before {
  content: ' ';
  position: fixed;
  top: 0;
  left: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  background-color: red;
  background-position: center top;
  background-repeat: no-repeat;
  background-size: cover;
  will-change: transform;

}
.Parallax h1 {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  color: #fff;
  width: 50%;
  height: 1em;
  text-align: center;
  z-index: 2;
}
p{
  color: #fff;
}
.Parallax-image-1:before {
  background-image: url(https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTqgknPHfXngK5Rm8foHqsR-K5J5yAKa-njp2XC5cGCjtmRo__KEw);
}

.Parallax-image-2:before {
  background-image: url(https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSwu_ZX03m-x1IOFgD38wHyuHkXbwSizX7PmHpW5phV3pQpoNqIpQ);
}
.imgoverflow{
height: 200px;
margin-top: -30vmin; 
}
<div id="content">
    <section class="Parallax Parallax-image-1">
      <h1>Title Text</h1>
    </section>

    <section class="Parallax">
    <img src="http://www.clipartbest.com/cliparts/ecM/d94/ecMd945ei.png" height="300px" class="imgoverflow">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    </section>

    <section class="Parallax Parallax-image-2">
      <h1>Title Text</h1>
    </section>

    <section class="Parallax">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </section>
</div>

Answer №1

actually this doesn't quite qualify as parallax effect ;)

but fear not, to achieve the desired effect, make these 3 adjustments:

  1. In the .Parallax:before section, change position: fixed to position: absolute

  2. Remove overflow: hidden from the .Parallax section

  3. Add the following rule to both .Parallax-image-1:before and .Parallax-image-2:before: position: fixed

Once done, your code should resemble the following:

html, body {
  height: 100%;
}
body {
  background: #f6f6f6;
  margin: 0 0 0;
  padding: 0;
}
#content {
  position: relative;
}
.Parallax {
  position: relative;
  z-index: 2;
  width: 90%;
  padding: 5%;
  height: 600px;
}
.Parallax:before {
  content: ' ';
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  background-color: red;
  background-position: center top;
  background-repeat: no-repeat;
  background-size: cover;
  will-change: transform;

}
.Parallax h1 {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  color: #fff;
  width: 50%;
  height: 1em;
  text-align: center;
  z-index: 2;
}
p{
  color: #fff;
}
.Parallax-image-1:before {
  background-image: url(https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTqgknPHfXngK5Rm8foHqsR-K5J5yAKa-njp2XC5cGCjtmRo__KEw);
  position: fixed;
}

.Parallax-image-2:before {
  background-image: url(https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSwu_ZX03m-x1IOFgD38wHyuHkXbwSizX7PmHpW5phV3pQpoNqIpQ);
  position: fixed;
}
.imgoverflow{
height: 200px;
margin-top: -30vmin; 
}

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

How to ensure a table in MaterialUI always maintains full width without requiring horizontal scrolling in CSS?

After attempting to allocate each widthPercent value on the TableHeader so they sum up to 100%, I am still experiencing the presence of a scroll bar. I have tried setting fixed widths for each column, but this results in excess space on the right side dep ...

What are the steps for creating an animated visualization of the peak chart?

As a newcomer to CSS and Javascript, I am currently struggling with animating a peak (bar) chart that I came across on codepen. If anyone can provide assistance or guidance, it would be greatly appreciated! The chart can be found here: http://codepen.io/An ...

What could be the reason my checkbox won't check using jQuery?

Currently, I am using kojs within my Magento 2 project. I have implemented a method that successfully shows and hides an input box based on user interaction. However, despite the function working as expected, the checkbox does not display its checkmark. D ...

Fill the center circle with GoJs background

Is there a specific way to paint the center circle only? I have provided an example project below. ...

Emphasize user-entered text using HTML and CSS

Here's a scenario: a text paragraph is displayed alongside an input box. The user must type the same text into the input box as shown in the paragraph. I'm aiming to highlight the paragraph text in color as the user types, to demonstrate progres ...

tips for rotating a bootstrap background image

I would like to know if it is possible to flip the background image of a section that contains both a navbar and a row in Bootstrap 5. I am aware of using <<transform: scaleX(-1)>> but this flips all the container elements. Is there a way to ac ...

How can you prevent a tag from firing in Google Tag Manager by identifying a particular script included in the HTML code

Seeking advice on modifying our Google Tag Manager container as I am a novice when it comes to GTM. Encountering an issue with IE8 on pages utilizing Fusion Charts resulting in a javascript error in gtm.js. Upon investigation, it appears to be related to a ...

A straightforward jQuery conditional statement for dynamically generated content

If the div '#ajax' contains content, I want to make the div '.container' clickable. Here is the basic jQuery script I have implemented: if ('#ajax:empty') { $('.container').css('pointer-events', ' ...

Angular is having trouble with the dropdown feature when using Semantic UI

I'm having trouble with the dropdown not displaying any items when I click on it. Here is the source code for reference: <div class = "ui centered grid"> <div class = "ten wide column"> <form class = "ui form"> <h4 cl ...

Using jQuery for slide shows in Ruby on Rails framework

I'm attempting to create a slideshow using jQuery and have the images stored in an array. However, I'm struggling with the implementation of the slideshow functionality. I've checked out 'http://jquery.malsup.com/cycle/' for guidan ...

Alter the path within a paragraph tag in html

I'm having some trouble changing the direction of a tag inside another tag. It's not working correctly for me. In the example below, I want to see aslami @ exactly as I have written it, but the result is showing @ before a instead of after i. ...

What is the best practice for adding a DOM element at a precise location within an ng-repeat loop?

I am currently working on developing a podcast player application using AngularJS. At this point, I have successfully created a list of available podcasts that can be played, utilizing ng-repeat. The code for the list is shown below: <ul ng-controller ...

Change the left position of the sliding menu in real-time

I am currently designing a website with a sliding menu feature. By default, the menu is set to -370px on the left, displaying only the "MENU" text initially. When a user hovers over the menu, it expands to the right, allowing them to select different menu ...

Unexpected Error with Background Position Variable

Hello, I am attempting to create an animated background effect that moves up and down using the .animate() and .hover() methods in jQuery. Within my DOM, there is a div with id="#menu" containing a UL list where each item has a background positioned at dif ...

What is the reasoning behind beginning the transition with autofocus enabled?

After creating a contact form with autofocus="autofocus", a strange behavior was noticed. It seems that when the form has autofocus, the transition effect on the navigation bar is triggered in Firefox only. Is this an error on my end or just a bug specific ...

Displaying a loading indicator as content loads within the iframe

How to Display a Loading Indicator During Content Loading Within an iFrame: 1) When a postback or submit event occurs within a form inside the iFrame ...

Experience the magic of Materialize CSS SideNav

I'm currently attempting to implement the mobile side navigation provided by Materialize. I've managed to display the menu icon, but when I click on it, nothing happens. It seems like the function is not being triggered, and there are no errors s ...

Styling with CSS: How to Adjust Word Wrap in a Container that Resizes Dynam

I'm struggling to ensure that long lines of text break and wrap correctly within a chat feature I am developing. The crucial elements in question are .chat__messages__item and .chat__messages__body (these are all contained within a parent element set ...

Update overall font size to be 62% for a consistent look across the website

Recently, I developed a browser extension that adds an overlay button to the LinkedIn website. Everything was running smoothly until I discovered that LinkedIn uses a global font-size: 62,5% that completely messes up my design.. https://i.stack.imgur.com ...

Error message in JS and HTML is totally bizarre

My expertise in JavaScript is very limited, so the terms I use might not be entirely accurate. However, I'll do my best to explain the issue at hand. I'm facing a peculiar problem... I've been attempting to modify someone else's JS scr ...