Can someone guide me on how to create scrolling effects for my content? [html/css]

insert image description here

Image dedicated to MrXQ

I require assistance in verifying the accuracy of the following code - all content displayed below has been altered from the original for privacy concerns

My objective is to have the headers scroll over the trollface, which is positioned one z-index lower than the headers. The trollface should remain stationary while the headers are visible initially on the screen. As you scroll up, the "test" text in the brown box should gradually appear from the bottom

I am uncertain if my approach is correct; I have incorporated concepts like parallax scrolling, fixed and relative positioning, and adjusting z-indexes for the headers. However, I am unsure about the terminology for bringing up the brown box from the bottom as you scroll; does it involve overlaying?

.parallax{
background-image: url("https://upload.wikimedia.org/wikipedia/en/thumb/9/9a/Trollface_non-free.png/220px-Trollface_non-free.png");
min-height: 500px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}


h1{
color: black;
font-family: 'Quicksand';
font-size: 50px;
text-align: center;
z-index: 1;
position: relative;
}

h2{
color: black;
font-family: 'Arial';
font-size: 25px;
text-align: center;
z-index: 1;
position: relative;
}

.textbody{
position: relative;
}

.textbodytext{
color: white;
font-family: 'Quicksand';
font-size: 50px;
text-align: center;
z-index: 2;
position: relative;
background: brown;
}
<DOCTYPE! html>

<html>
<head>
<title>TITLE</title>
</head>

<link href="maintenance1.css" rel="stylesheet" type="text/css">

<body>

<div>
<body class="parallax"></body>
</div>

<div>

<body  class="textbody">
<h1>This is a header</h1>
<h2>This is a smaller header</h2>
<p class="textbodytext">
Test test test test test Test test test test test Test test test test test Test test test test test Test test test test test Test test test test test Test test test test test Test test test test test Test test te...
</p>
</body>
</div>

</body>
</html>

Relevant image provided in response to a commenter, options discussed in the comments

Update: After modifying the font-size of the brown box to 50px, I tested the confidential actual code and found that most parts of the background image were still visible, with the brown box covering key areas

Upon reflection, I now realize that I want only the background visible at first, centered with the headers, and then as you scroll up, the brown box should emerge from below the browser, initially invisible but becoming visible upon scrolling up

Answer №1

If this is close to what you're looking for, let me know. If not, please leave a comment below with the specific changes you have in mind.

    var didScroll;
        var lastScrollTop = 0;
        var delta = 5;
        var navbarHeight = $('#navi').outerHeight();
        $(window).scroll(function(event){
            didScroll = true;
        });

        setInterval(function() {
            if (didScroll) {
                hasScrolled();
                didScroll = false;
            }
        }, 250);

        function hasScrolled() {
            var st = $(this).scrollTop();
            
        
            if(Math.abs(lastScrollTop - st) <= delta)
                return;
            
        
            if (st > lastScrollTop && st > navbarHeight){
               
                $('#navi').css('top','-60px');
            } else {
               
                if(st + $(window).height() < $(document).height()) {
                    $('#navi').css('top','0');
                }
            }
            
            lastScrollTop = st;
        }
ul{
    list-style-type: none;
}
.header-box{
    position: relative;
    width: 100%;
    height:100vh;
    
    overflow: hidden;
    text-align: center;
    box-sizing: border-box;
    color: #ffffff;
    font-weight: 500;
    font-size: 2em;

    background-color: #4f4f4f;
}
.header-box .img{
    width:100%;
}
.header-box header{
    position: fixed;
    top: 0; 
    z-index: 999;
    width: 100%;
    height:60px; 
    text-align: center; 
    -webkit-transition: top 0.2s ease-in-out;
    transition: top 0.2s ease-in-out;
  background-color: #fff;
}

.header-box header ul{
    display: inline-block;
    padding: 0;
}
.header-box header ul li{
    float:left;
    font-size: 15px;
    list-style: none;
    margin: 0 15px;
}
.header-box header ul li a{
    color: #000000;
    text-decoration: none;
    font-weight: 500;
}
.header-box header ul li a:hover{
    color: #7d2516;
    text-decoration: none;
    font-weight: 500;
}

.header-box .header-text{
    position:absolute;
    top: 100px;
    z-index: 999;
    width:100%;
    height:300px; line-height: 50px;
    font-size: 1.3em;
    color: #eeeeee;
}
.header-box .header-text small{
    font-size: .5em;
    color: #ffffff;
    font-weight: lighter;
}

.body{
  width:100%;
  height:1000px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<div class="header-box" id="home">
        <header class='nav-down' id="navi">
            <ul>
                <li><a href="#">Header</a></li>
            </ul>           
        </header>
        <div class="header-text">
        <h4>Body</h4>   
        </div>
    </div>
  <div class="body">
  </div>
 
 </body>

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 is the solution for fixing scrolling while keeping the header fixed and ensuring that the widths of headers and cells are equal?

Is there a way to set a minimum width for headers in a table and provide a scroll option if the total width exceeds 100% of the table width? Additionally, how can we ensure that the width of the header and td elements are equal? Below is the HTML code: ht ...

Saving sortable portlet items to a database using JQuery AJAX

I've searched through numerous resources to find a solution to my problem, but none of them have been successful. Here is the code I am working with: http://plnkr.co/edit/pcfz33lzHz4wdehjGEuQ I am trying to utilize AJAX to save the order of two port ...

``There seems to be an issue with CSS Transform/Transition not functioning properly

Here is some CSS code that I used to animate a list of items on my website: selector { display: flex; } #primary li a { -webkit-background-clip: text; -webkit-text-fill-color: transparent; ...

Text that disappears upon clicking on show/hide按钮

Could someone please help me figure out how to prevent the "See more" text from disappearing when clicked in the example below? I want it to stay visible. Thank you! ...

Ways to stylize bullet points in lists with CSS in HTML document

I am currently working on a Q&A page using simple HTML. This is the current appearance of my page. Check it out here on JSFIDDLE. My task involves adding an 'A' to the answer for each question. Some answers have multiple paragraphs, so the ...

A single button that performs multiple actions with just one click

Summary: Seeking assistance in implementing a button that triggers three different actions upon being clicked thrice. Detailed description: On one page of my website, there is an introduction with text and images. I currently have a button that switches t ...

Customizing color schemes of bootstrap buttons and dropdown-toggle elements

My button group looks like this: HTML <div class="btn-group"> <button type="button" class="btn btn-default btn-xs red-outline-button"> Sync </button> <button type="button" class="btn btn-default btn-xs gold-outline-button" da ...

What is the best way to keep a <div> class anchored to the bottom of an HTML page?

I am looking to incorporate a footer into my website that stays fixed at the bottom of the screen. However, I have encountered an issue: Here is what I have attempted so far: .footer { position: absolute; width: 100%; background: #0084FF; ...

Tips for Including a Parallax Image Within a Parallax Section

Currently, I am working on implementing a parallax effect that involves having one image nested inside another, both of which will move at different speeds. My progress has been somewhat successful, however, the effect seems to only work on screens narrowe ...

Web browser control in WinForms fails to trigger the document complete event on an AJAX website

My VB.Net desktop application utilizes the IE browser control to browse the web. Typically, when a regular page is loaded, the document_complete event triggers and allows me to access the resulting page content. However, I'm encountering a problem wit ...

Utilizing CSS to create a zoom effect on hover for an image while preserving its original size was successful, however, the issue arises as only a corner of the image is visible

On my webpage, I have implemented an image that zooms in slightly when hovered over. Unfortunately, this animation has caused the image to only display one part regardless of whether hover is activated or not. I've attempted to troubleshoot by adjusti ...

Guide for changing the background color exclusively in the final row of a dynamically-generated HTML table with PHP

<table width="100%"> <tr> <? $count=0; $i=1; foreach($gallery as $key => $list1) { $count++; ?> <td> <img src='<?echo base ...

Struggles encountered while developing a JavaScript calendar

Hey guys, I'm encountering an issue with Uncaught TypeError: document.getElementById(...) is null. I believe the problem lies in the way types are being parsed for document.getElementById(dayOfWeek).appendChild(dayPTag);. This code is meant to display ...

Exploring various viewport dimensions using Django and Selenium

I am currently experimenting with testing the characteristics of specific UI elements at various viewport sizes and media query breakpoints defined in CSS. Initially, I have a setup function that initializes a headless Chrome browser with what I believe is ...

What is the best way to store HTML code in a SQL Server database to ensure proper rendering?

My website is currently in development and is similar to Stack Overflow. I am using a simple textarea for text input as opposed to a WMD editor like the one used on Stack Overflow. When I enter HTML code as input and store it in my database table under a ...

What causes my words to link together, and what is the term for this phenomenon?

Is there a specific term for the way my font is changing automatically? How can I emulate this effect on other text? And how do I remove it if needed? https://i.sstatic.net/yIe2f.png ...

Is it possible to create editable Word documents programmatically in ASP.NET?

The goal is to create proposal documents that can be easily modified in Word before sending them to customers. Most of the proposal content will come from existing HTML website material (CMS) and some custom content for specific situations. Conditional lo ...

Update the class name of an element depending on the URL

Hey there! I'm working on customizing the style of some elements (specifically tds within a table) based on the current URL. Here are the pages I'm targeting: http:\\domain\site\welcome.html http:\\domain\site& ...

Using jQuery to target a specific item from a retrieved list of elements

I'm currently working on a photo gallery feature that is reminiscent of Instagram or Facebook user photos. My goal is to enable users to view details about each image (such as the date) in a box that appears over the image when they hover over it. E ...

Twitter Bootstrap 3 Carousel now showcasing a pair of images simultaneously instead of three

Can this carousel be configured to show just 2 pictures at a time instead of 3? Check out the live demo here. I've attempted adjusting the columns to col-md-6 and the CSS to 50%, but haven't had any success... ...