Alter the color of a sticky element by scrolling down with the mouse and hovering over the colored sections

Apologies if the title is a bit vague. I have a sticky element and I'm interested in changing its color to white when it passes over a section/div of a specific color. Is this achievable?

Answer №1

Here is a demonstration based on your query.

I have utilized this instance: sticky element example html.

 window.onscroll = function (event) {
    document.getElementById('stickyEl').style.backgroundColor = 'green';
};
div.sticky {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    background-color: yellow;
    padding: 50px;
    font-size: 20px;
}
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

    <h2>Sticky Element: Scroll Down to See the Effect</h2>
    <p>Scroll down this page to see how sticky positioning works.</p>
    <div id="stickyEl" class="sticky">I will stick to the screen when you reach my scroll position</div>

    <p>Some dummy text..</p>
    <h2>Scroll back up again to "remove" the sticky position.</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.... (Content truncated for brevity)

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

What could be the reason behind Google and Bing's mobile-friendly tests inaccurately flagging my site as non-mobile friendly?

Our website for resources is responsive and has been thoroughly tested on various real smartphones, including iPhone, Android, and Windows devices. It looks great on every phone we've tested it on. You can visit the resources website here: The site ...

Tips for effectively showcasing icons on buttons

I am experiencing issues with my code that is causing icons to be displayed incorrectly, appearing in the upper left corner and cut off rather than being centered and fully shown. <link rel="stylesheet" id="simple-css" href="//cdnjs.cloudflare.com/ajax ...

Tips for building nested columns within React Bootstrap Table

I have been working with react bootstrap table, you can find more information here You can check out the code in action by clicking here My goal was to create a table that resembles the one shown below: https://i.sstatic.net/jsZKe.png Here is an example ...

Mapping data to the user interface using React.js

I’m completely new to using the react.js library and I’m currently working on creating a simple CRUD application. In my project, I’ve added a file called dataprovider.js. export function getCrudData() { axios.get('https://api.github.com/us ...

Tips for modifying a particular element within a class?

I am seeking guidance on how to modify a specific class attribute in CSS/JS/JQuery when hovering over a different element. Here is an example: <h1 class="result">Lorium</h1> <h1 class="result">Ipsum</h1> <h1 class="result">Do ...

Learn the method to conceal rows within a table simply by toggling a button

I need a function that will hide the rows below a row with a header and button, and only reveal them when another row with a header and button is clicked. When one of the +/- buttons is clicked, it should hide or expand all the rows with data content. http ...

Is there a way to initiate an Edge animation when an onclick event occurs?

I am interested in incorporating an interactive Adobe Edge animation that activates upon the click of a conventional HTML form button. Could you please guide me on how to achieve this? ...

Design portions of text that are not enclosed in a div element

Currently, I am retrieving data from an API through a SOAP call. After pulling in the data, the resulting HTML structure appears as follows: <div class="component_wrapper"> 2 man Teams<br> 20 Min AMRAP<br> 50 Double Unders<br> 50 ...

What is the method for copying table data, including input text as cells, to the clipboard without using jQuery?

I have a basic table that looks like this: <table> <thead> <tr> <th>Savings</th> </tr> </thead> <tbody> <tr> <td>Savings <button type="button" (click)=" ...

Using JavaScript's DOM manipulation to switch out one HTML tag for another

As a newbie to javascript and DOM, I'm facing an issue with manipulating DOM elements using javascript in the given HTML code. <html> <head> <title>Testing</title> </head> <body> <marquee direction=up heig ...

What is the best way to center a div vertically on the page?

I've utilized Bootstrap 3 to create this row: <div class="cart"> <div class="row border"> <div class="col-md-8 desc pad itemsheight"> <div class="col-md-12"> <!-- react-text: 141 -->Docos <!-- /react ...

Please submit the form only after checking the appropriate checkbox

I am encountering an issue with form validation. In the first image, users can make a choice that will determine the display of either form 2 or form 3 (shown in images 2 and 3). The fields in each form are marked as mandatory but both sections start as ...

Issues with navigating sliders

I've encountered a problem with my slider arrows while following a YouTube tutorial. They are supposed to appear next to the picture and testimonial, but instead, they are showing up at the top. This issue wasn't present initially, but after enco ...

Troubleshooting Bootstrap: Identifying errors in my bootstrap code

Could you help me diagnose the issue with this code? I have tailored it to be responsive on my tablet by using 12 columns for two divs, expecting the third div to be in a new row. However, upon checking my index.html on the tablet, all the divs are display ...

Adjust the width of the element to match the size of the image within

My webpage features an image along with some accompanying metadata that I want to be centered on the page. I want the div holding the metadata to be the same width as the image. Here's an example: Unfortunately, I am unable to determine the image&apo ...

Issue alert with Vue animations

I have created a functional demonstration of VUE JS menu animation. However, I am encountering an issue due to having two root elements inside the menu component, resulting in the following warning: [Vue warn]: Runtime directive used on component with no ...

How can I ensure the dialog title and button are centered, and how can I center a JQuery dialog box after the browser has

My current issue involves creating a dialog with centered text, but I'm struggling to achieve the same effect with the title and button. Additionally, the button I've created doesn't seem to be functional when placed in the dialog box. Despi ...

Height of Nav-Links in Bootstrap 4

Is there a way to modify the height of the navigation links in Bootstrap? To set a specific height, such as for the navbar, you may encounter issues where it doesn't occupy the entire space. CSS CODE: .navLogo { width: 15%; height: 100%; } ...

Custom fields in DataTables

Currently, I am in the process of building a web application that utilizes jQuery datatables and involves accessing JSON objects. Below is the code snippet where I attempt to assign a specified checkbox: "aoColumns": [ { "mData": '<input type ...

Enhancing reader experience with AMP image optimization

My website features AMP pages that provide editors with the ability to insert images into the content. These images are shown using an amp-img element and appear properly in regular browsers. However, when viewed in reader mode or when crawled by services ...