The overflow hidden property does not seem to be effective when used in conjunction with parallax

The issue arises when I attempt to use the overflow hidden property in combination with parallax scrolling.

Although everything seems to be working correctly with JavaScript for parallax scrolling, setting the overflow to hidden does not contain the image within the div as expected.

Below is the HTML code snippet:

<div id="page2">
       <p id="bb">The title</p> //Some title
       <div id="bg"></div> //Blue box in front of the image(design decision)
       <img src="img/Food.jpg" alt="prlx" id="prlx"/> //The image which has the propery
</div>

Here is the JavaScript eventListener and function:

window.addEventListener("scroll",func,false);

function func(){
      prlx_lyr_1 = document.getElementById("prlx");
      prlx_lyr_1.style.top = (window.pageYOffset/4)+"px"
}   

Additionally, here is the CSS styling for the image in question that I am trying to hide any overflowing parts:

#page2 img{
      position:relative;
      top:-300px;
}

Furthermore, this is the CSS for the div containing the image:

#page2{
      overflow:hidden;
      height:250px;
}

There are some extra CSS rules pertaining to the #bg element.

Update: The js fiddle link provided displays how the container div's overflow is not properly hidden.

Please refer to this js fiddle link for a closer look at the issue.

Answer №1

It appears that the issue arises when using position: fixed as it removes the element from the document flow, unlike absolute which can be contained within a parent using relative. A solution is to set the image as a background on a div with position: absolute:

HTML

<div id="page2">
   <p id="bb">The chef</p>
   <div id="bg"></div>
   <div id="bg-image"></div>
</div>

CSS

#page2{
  overflow:hidden;
  height:250px;
  position: relative;
}

#bg{
  background: #33c1c9;
  height:250px;
  width:100%;
  position:relative;
  z-index:74897;
  opacity:0.4;
}

#bg-image{
  background: url("http://im47.gulfup.com/1Y5tcL.jpg") no-repeat fixed;
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
}

FIDDLE

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

Leverage socket.io in various routes within a node.js application

In my Node.js application, I have various routes defined in the router.js file. Now, I want to implement socket.io in every route to enable real-time communication between my Node.js and React.js applications. However, the structure of my Node.js applicati ...

What steps should I take to troubleshoot and fix the issue of data insertion errors in

I am encountering an issue with a PHP form that is supposed to transfer information to a database after submission. However, every time I press the submit button, I receive an error message. Can anyone help troubleshoot this problem? ...

Are there any methods to improve the coding, align images to the center, and ensure that elements stay in their designated positions?

Is there a way to tidy up the code, center images, and keep everything in place? This is the look I desire: The main outer box should remain centered on the browser page. Pause, play, and stop buttons should float to the left of the box. My image sh ...

Access the API data by sending requests with the required headers which include the GUID, Username,

Assigned the task of creating a website that relies on fetching vehicle stock data from an API, I find myself struggling with this particular API. Despite my previous experience with various APIs, this one is proving to be quite challenging. Unfortunately, ...

Can these two arrays be merged together in JavaScript?

Here is the structure of the first array: [ 0:{program: id_1}, 1: {program: id_2} ] Now, let's take a look at the second array: [ 0: [ 0: {lesson: name_1}, 1: {lesson: name_2} ], 1: [ 0: {lesson: name_3} ] ] I am attempti ...

What could be causing the styled-component's flex value to not update?

I have a sidebar and main content on my website layout. The main content occupies most of the screen space, while the sidebar should only take up a small portion. Both elements are within a flexbox container, with the sidebar and main content as child divs ...

Is there a way to ensure that the text stays positioned behind the initial image even as the window size is adjusted

<html> <head> <title> Example </title> <style> img:hover {opacity : 0.3;} img {z-index : 1; height : 33%; width : 33%; } .first { position : absolute; top: 0%; left: 0%;} .second {position : absolute; top: 0%; left: 33%; ...

Is it possible to execute this animation with a single click for repetitive playback?

CODEPEN const btt = document.querySelector('.btt'); btt.addEventListener('click', function(){ this.classList.toggle('anime'); }); Is there a way to achieve the desired effect with just one click? ...

Tips for executing jsfiddle code within Joomla 3.2

I'm having trouble executing this code on my Joomla website. I have Joomla 3.2 installed with the JCK Editor, but the HTML tags are not functioning correctly. Can someone please assist me in running the following code: $("#text10").keyup(functio ...

My Javascript code is being modified by Wordpress to include '<p>' tags

Using the philantrophy theme, I incorporated sliders into a page using shortcodes and encountered an issue where p tags were automatically inserted into my javascript code. The following code snippet highlights the unwanted p tag added in my javascript: ...

Discover the steps for dynamically adding a new row in an Angular application

I am trying to add new rows to a table in Angular, but I'm having some trouble. Initially, there is one empty row, and when I click on the "add new" button after entering details, a new row should be added. I was able to do this using jQuery, but I&ap ...

Ensure that the width of the checkbox label in HTML/CSS using Bootstrap remains consistent and fixed, regardless of

Seeking assistance for a bootstrap checkbox button behavior. Currently, the text on the button changes when clicked, but I would like to set a fixed width for the button regardless of the text length and center the text inside it after clicking. Any guidan ...

Cannot locate JSON file in NodeJS

Currently, I am developing an express API and looking to establish a connection with a MySQL server using this API. The configuration settings are stored in a file named settings.json. To retrieve these settings, I am utilizing the following code: const c ...

Transforming JSP style tags into CSS declarations

Within my JSP file, I have various tags that look like this: <style type="text/css"> #mask { display: none; cursor: wait; z-index: 99999; position: absolute; top: 0; left: 0; height: 100%; ...

Activate the mouseenter event as soon as an animated element makes contact with the cursor

As I venture into the world of web development, I am currently working on creating a game where the main objective is to avoid touching moving circles with the cursor. My approach involved using a mouseenter event as shown in the JSFiddle example below: $ ...

SVG path with dynamic elements

Consider the following SVG: <svg xmlns="http://www.w3.org/2000/svg" width="237" height="129" viewBox="0 0 237 129" fill="none"> <path d="M228 1H9C4.58172 1 1 4.58172 1 9V91V104V127L20 111.483L228 112C232.4 ...

What is the best way to handle the keystroke event in a $.bind method?

I'm struggling with passing a specific keystroke through the bind method. $(document).bind('keyup', event, keyup_handler(event)); This is my attempt at solving it.. Here is the function it should be passed to: var keyup_handler = functio ...

Dropdown in Bootstrap partially obscured by content on page

I have made some adjustments to my Bootstrap dropdown menu: The dropdown now appears when hovering, rather than clicking The li that triggers the dropdown is still clickable Although the dropdown is functioning correctly, there is an issue where it disa ...

Utilize Selenium to extract information from a webpage, including content that is dynamically generated through JavaScript

Currently, I am facing a dilemma: my desire is to extract information from a webpage (for example, this one) regarding the apps that are available, and then store this data into a database. In my quest to achieve this task, I have opted to use crawler4j t ...

Prevent dropzone from refreshing the page

For the past few days, I have been scouring the internet for solutions on how to prevent a page from automatically reloading after an upload. Despite finding various methods, I have been unsuccessful in resolving this issue. Although I am following the st ...