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

Switch between the inner unordered list

Take a look at this Fiddle http://js-fiddle.net/jVfj5/ My goal is to have the Sub Categories (Nested Ul) display when I click on Services, while they are hidden by default. Additionally, only the ul under Services should open, not all the other ul's ...

Is it possible to use JavaScript to forcefully transition a CSS keyframe animation to its end state?

One dilemma I am facing involves CSS keyframe animations triggered by scroll behavior. When users scroll too quickly, I would like JavaScript to help send some of the animations to their 'finished/final' state, especially since the animations bui ...

Can you explain the purpose of the behavior: url(); property in CSS?

While browsing the web, I came across a CSS property that caught my eye. It's called behavior, and it looks like this: #element{ behavior: url(something.htc); } I've never used or seen this property before. It seems to be related to Internet ...

Steps to include a title next to a progress bar:

Is there a way to achieve something like this? I attempted to use bootstrap but I ran into an issue where the title was slightly misaligned below the progress bar. Can someone offer assistance with this matter? Apologies if this has been asked before. H ...

The jQuery attr() method is universally compatible across platforms and stands independent

I have a jQuery statement that is currently working for me, but I am unsure if it is cross-platform independent. Can anyone confirm? $("input[name='confirmed']").attr("checked",false); It is functioning correctly on the latest version of Firefo ...

Is there a way to set the starting position of the overflow scroll to the middle?

Is there a way to have the overflow-x scrollbar scroll position start in the middle rather than on the left side? Currently, it always begins at the left side. Here is what it looks like now: https://i.stack.imgur.com/NN5Ty.png If anyone knows of a soluti ...

Adjusting the image placement within a modal window (using bootstrap 3)

Behold, an example modal: <!-- Large Modal --> <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> <div class="modal-dialog modal-lg"> <div class="modal-content"> ...

Notification continuously appears when clicking outside of Chrome

I have implemented the use of onblur on a text box to display an alert. However, I encountered an issue where if I click outside my Chrome browser after entering text in the text box and then click on the Chrome browser button in the task bar, the alert ap ...

Navigating to two separate webpages concurrently in separate frames

I am working on creating a website with frames, where I want to set up a link that opens different pages in two separate frames. Essentially, when you click the link, one page (such as the home page in a .html file) will open in frame 1 on the left side, ...

"Trouble with getting the Twitter Bootstrap dropdown menu to function properly

Currently, I am facing a challenge with my project as the dropdowns on the menu are not functioning properly. Despite having all the necessary files included, it seems like there might be an issue within my code. You can view the page here: (please try t ...

Background images at 100% width are not causing horizontal scrolling issues

I've come across an interesting problem. I created a quick screen recording to illustrate: Essentially, when you specify a min-width and the viewport width falls below that limit, a horizontal scroll bar appears. This behavior is expected, but when s ...

Struggling to make HTML5 validation function properly

I'm struggling to make HTML5 validation work in conjunction with AngularJS. Instead of displaying the error message, the form is submitted even when a field is required. If anyone has any insights on how to successfully implement HTML5 validation wi ...

Steps for implementing remote modals in Bootstrap 5 using CS HTML

I'm attempting to implement a remote modal window in Bootstrap 5 with C# MVC. The endpoint for the modal partial view is configured correctly. According to this discussion on Github, all that needs to be done is to call some JavaScript. However, it ...

Are there any better methods for creating div backgrounds and borders using CSS?

Within my application, there exists a multitude of div elements that share identical backgrounds and borders but vary in size. Having to utilize the same background image for each individual div proves to be highly inefficient, particularly in terms of ba ...

Material-UI LeftNav with a sticky header

I attempted to create a fixed header, specifically a Toolbar, inside a LeftNav so that when the LeftNav is scrolled, the Toolbar remains in place. However, for some reason, setting position: 'fixed' on the Toolbar does not work within the LeftNav ...

Encountering difficulties triggering the click event in a JavaScript file

Here is the example of HTML code: <input type="button" id="abc" name="TechSupport_PartsOrder" value="Open Editor" /> This is the jQuery Code: $('#abc').click(function () { alert('x'); }); But when I move this jQuery code to a ...

Struggling with implementing the use of XMLHttpRequest to transfer a blob data from MySQL to JavaScript

I have a blob stored in my local WAMP64/MySQL server that I need to retrieve and pass to an HTML file using XMLHttpRequest. I know I should set responseType="blob", but I'm not sure how to transfer the blob from PHP to JavaScript in my HTML file. Any ...

Adjust the width of content within a wrapper using HTML and CSS to automatically resize

I am facing an issue with a content div that has variable length content arranged horizontally. I want the width of this content div to adjust automatically based on the length of its content. Removing the arbitrary "20%" value from the width property is c ...

How can I create a responsive input group with automatic width using Bootstrap 3.1?

I am having trouble with the layout of my two floating divs. The first div contains buttons and the second div contains an input-group. However, the input-group is moving down a line instead of utilizing the available space. Here is a link for reference: ...

Tips for confirming a date format within an Angular application

Recently, I've been diving into the world of Angular Validations to ensure pattern matching and field requirements are met in my projects. Despite finding numerous resources online on how to implement this feature, I've encountered some challenge ...