Dynamic website featuring fixed background with content transitioning through clicks or scrolls

Seeking a template or tutorial on how to create a website similar to the following examples:

The desired website layout would allow users to scroll through content while keeping the background neutral, with the option to click links that transition to new content but maintain a stationary background.

I have designed a portfolio site for myself with this effect in mind, however I am unsure of what it is called so I can learn how to code it. The main page would feature content with links on the right side, and as you scroll or click a link, the content smoothly transitions while the background remains fixed.

Hopefully this question is clear! Thank you!

Answer №1

When tackling your question, I typically approach it by stacking divs using the position: absolute property on top of each other. By toggling the active class, the visible element can be identified - ensuring that this class has a higher z-index value than the stacked elements. To set the initially visible element in HTML, simply add the active class to it. Subsequently, utilize JS to toggle the active class for elements. In my JS implementation:

jQuery: https://jquery.com/download/
jQuery Mouse Wheel Plugin: https://github.com/jquery/jquery-mousewheel

HTML:

<div class="container">
    <div class="vertically-stacked active"> //first visible banner
        <h1>Hello</h1>
    </div>
    <div class="vertically-stacked">  //visible only if class active is added
        <h1>World</h1>
    </div>
</div>

You may have an infinite number of vertically-stacked elements.

CSS:

.container    //container of vertically stacked elements
{
    position: relative    //or absolute but not static 
}

.vertically-stacked
{
    left: 0;
    opacity: 0;
    position: absolute;
    top: 0;
    transition: all .25s;   //time which takes to switch the active element
    -moz-transition: all .25s;
    -o-transition: all .25s;
    -webkit-transition: all .25s;
}

.vertically-stacked.active
{
    opacity: 1;
    z-index: 100;
}

JS:

$(document).on('mousewheel', function (e)
{
    var $verticallyStacked = $('.vertically-stacked'),
        oldActive = $verticallyStacked.index($('.vertically-stacked.active')),
        newActive;

    $verticallyStacked.eq(oldActive).removeClass('active');
    if (e.deltaY < 0) //scroll down
    {       
        newActive = oldActive + 1;
    }
    else //scroll up
    {
        newActive = oldActive - 1;
    }
    $verticallyStacked.eq(newActive).addClass('active');
});   

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

Exploring the process of web scraping from dynamic websites using C#

I am attempting to extract data from using HtmlAgilityPack. The website is dynamic in nature, displaying content after the page has fully loaded. Currently, my code retrieves the HTML of the loading bar using this method, but encounters a TargetInvocation ...

Retrieving a variable value from an AJAX call for external use

Looking for a solution to pass the generated JSON response from an ASMX web service accessed via AJAX to an outside variable in another function. Below is the code snippet for reference: function setJsonSer() { var strWsUrl = &apo ...

Retrieve the image and insert it using an img tag

Working on a project, I want to include Instagram profile pictures by embedding them. Although I have the image URL, I am struggling to integrate it into my HTML page. Take a look at this sample: This provided link displays the Instagram profile picture. ...

Is it possible for PHP to not provide an image to HTML?

I'm currently facing an issue trying to display an image in HTML using a PHP script. Despite my best efforts, it's not functioning as expected :-( Here is the code snippet from my image.php script: <? $_GET['f'] = 'all_thre ...

Enhance Vaadin 14: Automatically adjust TextArea size when window is resized

Using Vaadin 14.1.19 in a project called "My Starter Project," I attempted to create a TextArea that supports multiple lines. Initially, everything seemed fine, but upon resizing the TextArea, it failed to adjust the number of visible lines. Here is the co ...

What is the significance of using "your-shop" as the action form without a file extension?

I've come across filenames (with file extensions) or URLs inside the action attribute of a form, but I have never seen code like this before: <form action="your-shop" name="shop_name_form" id="shop_name_form" method="post" onsubmit="return check_s ...

Displaying notifications and opening pop-ups on a website through ajax can potentially cause the site to experience slowdowns or lead to

My website is built using Drupal. I have created a custom module that displays notifications in the browser and opens pop-ups on the website. I have implemented a JavaScript function that runs every 15 seconds, or less frequently if a condition is false o ...

Can transitions be applied to links in this manner?

Having an issue with ajax requests, I am currently resorting to using JavaScript linking. This is how I normally link: window.location.href = ('file:///android_asset/www/custom/kontakty.html'); I am curious if it's possible to add a transi ...

Include a class above the specified element; for instance, apply the class "act" to the "<ul>" element preceding the "li.item1"

Hello there! I need some assistance, kinda like the example here Add class and insert before div. However, what I really want to do is add the class "act" to a class above that matches the one below: Here's how it currently looks: <ul> ...

Identifying the clicked button with jQuery - can you guess which one?

On my webpage, there are dynamically generated buttons. I am looking for a way to determine the 'nth-child' that was clicked when one of these buttons is selected. <div> <button class="btn"></button> </div> <div> ...

Create your masterpiece on a rotated canvas

My goal is to draw on a canvas using the mouse, even after rotating and scaling the canvas container. The issue I am facing is that the mouse coordinates get affected by the rotation and scaling, making it difficult to draw correctly. I have tried switch ...

How to vertically align and center multiple divs with Flexbox programming

I have been grappling with the challenge of aligning two sets of rows vertically, each consisting of an image on one side and text on the other. While I usually use flex to achieve vertical alignment, it seems that a different approach is needed in this pa ...

Stopping an endless loop in JavaScript by pressing a key on the keyboard can be a useful

I've been working on creating a JavaScript game and am currently tackling the challenge of implementing gravity. One crucial aspect I need to address is creating an infinite loop without causing the browser to crash. Is there a way for me to include a ...

When Django comments go wrong: Issues with Ajax and CSRF verification

Having an issue here that seems a bit different from what others have encountered. I've gone through various answers but still no luck. Appreciate any assistance: I've got a list of News items resembling a Facebook feed, and each one has a comme ...

I'm looking for the location of Angular Materials' CSS directives. Where can I find them?

Currently, I am using components from https://material.angularjs.org/latest/ for a searcher project. One specific component I am working with is the md-datepicker, and I would like to implement some custom styles on it such as changing the background colo ...

Displaying Indonesian rupiah prices in jQuery using JSON data format

Here is some JSON data: {"grand_total":"1.200.000"} I need to display this JSON in $("jumlah").val(data.grand_total); Any suggestions on how to solve this? Thanks! ...

"Navigation Side Menu: w3-sidebar with hamburger toggle feature

If you are looking to implement the w3-sidebar, you can find it here: https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_sidebar_over The existing code uses a "hanburger" icon to open the side menu and a "Close X" menu item to close it. To simpl ...

Troubleshooting a CSS overflow problem in the main slider

While exploring the website , I encountered a minor issue. When I added "overflow: hidden" to the featured slider div, the images appeared stacked if JavaScript was enabled or the user's internet connection was slow. However, a new problem has arisen ...

What could be causing the validation messages to not display when utilizing Ajax in an ASP.NET Core application?

I have encountered an issue while using Ajax with my ASP.NET Core application. When I submit the form, the validation messages for invalid inputs do not appear as expected. Interestingly, when I disable AJAX, the validation messages start showing up. How ...

Hiding a Blogger section when its widget is not visible

Take a look at this code: <b:section id='page-list'> <b:widget id='PageList1' locked='false' type='PageList' version='2' visible='true'> </b:widget> </b:section> I wa ...