Verify whether a group of div elements overlaps a fixed div while scrolling

I have a layout with a list of posts and a logo positioned at the bottom of the page. The issue I am facing is that sometimes the title of the posts and the logo overlap, and I want to set the logo's opacity to 0.25 only when the text from .cat-date is above the .logo.

Despite trying to calculate the position from the bottom for each element, I am unable to achieve the desired outcome as the logo consistently remains at 0.25 opacity.

Any help or suggestions would be greatly appreciated!

$(window).scroll(function () {
    $('.cat-date').each(function(){
        var bottom = $(this).position().top+$(this).outerHeight(true);//distance from bottom
        if (bottom < 210){
            $(".logo").css("opacity","0.25");
        }
    console.log(bottom)
  })
});
.cat-date{
  height:50px;
  width:200px;
  color:blue;
  margin-bottom:150px;
  z-index:9999;
  position:relative;
}
.logo{
  height:50px;
  width:250px;
  background-color:red;
  position:fixed;
  bottom:50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div> 
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div>
<div class="logo"></div>

Answer №1

Check out this solution:

$(window).scroll(function () {
    var logoTop = $('.logo').offset().top;
    var logoBottom = logoTop + $('.logo').height();
    $('.cat-date').each(function(){
        var catTop = $(this).offset().top;
        var catBottom = catTop + $(this).height();
        if(catTop > logoTop && catTop < logoBottom || catBottom > logoTop && catBottom < logoBottom) {
            $('.logo').css('opacity', '0.25');
            return false;
        }
        else {
            $('.logo').css('opacity', '1');
        }
    });
});
.cat-date{//Simply delete the `height` attribute from the `.cat-date` selector
  width:200px;
  color:blue;
  margin-bottom:150px;
  z-index:9999;
  position:relative;
}
.logo{
  height:50px;
  width:250px;
  background-color:red;
  position:fixed;
  bottom:50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div> 
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div>
<div class="cat-date">lambada lambada</div>
<div class="logo"></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

Even after setting [attr.disabled]="false" in Angular, the Textarea still remains disabled

I am currently utilizing ngModel for a textarea, and I would like to be able to enable and disable the textarea based on a certain condition. Even though I have bound it correctly and the value is changing to [attr.disabled]="false", the textarea remains d ...

When attempting to execute an npm command, an error is encountered stating that chunk.sortModules is

It’s time to bring back an old project and make some modifications. I tried using git checkout 0.0.2 since that's the tag currently running on production, but it seems to be causing issues. After downloading the code to my PC, I removed the node_mo ...

Troubles with creating promises in Node.js

Currently, I am facing a challenge in Nodejs where I need to execute asynchronous tasks. Specifically, I need to navigate through all levels of a JSON object sequentially but synchronously. I am experimenting with the following code snippet, which is a si ...

Can Webpack be used to produce only CSS files without generating the output.js file?

I've integrated Webpack into my project alongside the extract-text-webpack-plugin. Within my project, I have various build scripts. One of these scripts focuses solely on bundling and minifying CSS. While utilizing Webpack for other tasks, I decided ...

The CSS selector functions as expected when used in a web browser, however, it

While conducting test automation using Selenium, I typically rely on css selectors to find elements. However, I recently came across a peculiar issue. I observed that in certain cases, the css selector works perfectly when tested in the browser console. Fo ...

Data storage in the database does not accommodate multiple rows

My current PHP setup includes the use of jQuery and Ajax for submitting multiple rows simultaneously. However, I am encountering an issue with the 'plantation_journal_no' key, which serves as both a primary key for plantation_journal_details and ...

Sorting an array of objects keys according to the position of keys in another array

I have two arrays: one with the correct order of keys and values, and another array coming from a backend in an unsorted format. let arr1 = ['name', 'age', 'occupation', 'address'] let arr2 = [{'age': 20, ...

Retrieving a database value in Node.js Firestore containing a space

Hello, I'm just getting started with node Js and I anticipate that it will be a smooth ride! Currently working on an application using node JS with Firestore where I need to retrieve data like "display name": James and "Age": 22 Since Age does not h ...

Moving data from one table to another and making changes or removing it

After successfully adding data from one table to another using .click, I encountered an issue. Whenever I utilize the search field in the top table, it clears the appended rows in the bottom table. I am looking for a solution to have these tables generate ...

What is the method for determining the overall page load time of a website, taking into account the total loading time instead of just the document.ready()

I recently attempted to create a function using either JavaScript or Python with Selenium to measure the page load time of a website. While document.ready() gives me the DOM load time, it may not capture AJAX calls that occur afterwards. I noticed there i ...

to invoke a jQuery function located on a different webpage

Imagine you have two web pages: hello.html and wow.html. hello.html contains the following script: <script> $(document).ready(function() { $( "#loader" ).load( "wow.html"); }); </script> while wow.html includes this jQuery function: $(fun ...

The chosen index in the Material Stepper feature is experiencing a malfunction

I've been busy working on a Mat-Stepper, actually two of them. I have a component that contains two ng-templates set up like this: Question: Why is my selected index not functioning as expected? Am I missing something? I know you can define [selected ...

5 Simple Steps for Adding a Value to a Popup Textbox Automatically

I want to send a value to another php page and then display the values. How can I achieve this? Here is the PHP code snippet: if(!empty($_POST["mytext"])) { for ($x=1; $x<=$a; $x++) { echo $txtLine[$x] = $_POST['mytext'.$x]; } } B ...

Working with Angular: Accessing SCSS variables from style.scss using JavaScript inside a component

I am working on an Angular 9 application that utilizes Angular Material and has two themes, namely dark and light. These themes are defined in the style.scss file as follows: $rasd-dark-text-color: mat-palette($mat-grey, 300); $rasd-light-text-color: mat-p ...

Utilize JQuery UI dialog to display a confirmation dialog and return either true or false based

My plan is to submit a form only after validating it properly. To achieve this, I will first use an ajax post request to check for any duplicate values in the form. If duplicates are found, the ajax call will return HTML code; otherwise, it will return &ap ...

Is it possible to create a CSS1 sprite animation triggered by a mouse hover

Is there a way to create sequential image loading on mouse hover for a CSS1 Sprite, similar to an animation? Please refrain from suggesting CSS3 solutions as not all browsers fully support CSS3 animations. Thank you. ...

Component cannot be shown on the screen

<template> <div v-for="corpus in getCorpora" v-bind:key="corpus.id"> <Corpus v-bind="corpus" /> </div> </template> <script> import Corpus from "../components/Corpus"; impor ...

Is an Event Bus necessary for sibling communication? Or can a parent send its data as a prop instead?

After watching a tutorial on using an event bus to communicate between sibling components in Vue, I came across an interesting approach. The tutorial demonstrated passing data from a parent component to child components as props, then modifying that prop i ...

"Escaping from the typeahead feature in Angular-UI Bootstrap results in the input field value becoming

Having some difficulty solving a particular edge case scenario. When I select a value from the dropdown of the typeahead using either the keyboard or mouse, the ng-model in the input field is populated correctly. However, if I type a few letters and then ...

Having trouble displaying API JSON data in a Vue.js table component

In my HTML file, I have implemented fetching data from an API and displaying it in a table successfully. Now, I am trying to convert the HTML file to use Vue.js, but encountering some issues. Despite being able to fetch data from the API with Vue, the tab ...