Scroll to Reveal Content Hidden Behind Hero Image

I am absolutely enamored with the Beautiful Stories section on Medium's website. The way they showcase their content is just mesmerizing.

One thing I've noticed is how the cover image and preview of the content changes as you resize your browser window. It's like magic!

Curious to know how they achieve this effect, I decided to set up a CodePen with my own page structure to experiment: http://codepen.io/realph/pen/luwdJ

If anyone has any insights on how I can replicate this amazing feature, please share your knowledge. Thank you in advance!

Answer №1

Give this a try,

new and improved

$(document).ready(function() { 
        var $winwidth = $(window).width();
        $("img.source-image").attr({
            width: $winwidth
        });
        $(window).bind("resize", function(){ 
            var $winwidth = $(window).width();
            var $winheight = $(window).height();
            $("img.source-image").css({
                'width': $winwidth,'height':$winheight
            });
         });
    }); 

The script above adjusts the image width based on the screen size.

Also, here is the CSS styling

img.source-image {
    position: absolute;
    top: 0;
    left: 0;
}

Or you can use

#img.source-image {
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

For more information, check out this Link

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

Creating dynamic elements in JavaScript and assigning them unique IDs

Hi there, I'm currently working on a project that requires generating dynamic divs with a textbox and delete button inside each one. The challenge I'm facing is figuring out how to assign a unique ID to each textbox element so that I can properly ...

Is it considered fashionable to utilize HTML5 data attributes in conjunction with JavaScript?

Currently, I am utilizing HTML5 data attributes to save information such as the targeted DOM element and to initialize events using jQuery's delegation method. An example of this would be: <a href="#" data-target="#target" data-action="/update"> ...

Seeking an efficient localStorage method for easy table modification (HTML page provided)

Currently, I am in the process of developing a custom 'tool' that consists of a main page with a menu and several subpages containing tables. This tool is intended for composing responses using prewritten components with my fellow colleagues at w ...

How do I set up a 5 column layout for the home page and switch to a 4 column layout for category pages in Magento?

Is it possible to display 5 columns of products on the Magento home page and only show 4 columns in the category area, or is this a pre-set parameter that applies platform-wide? ...

Retrieving Google Maps Geocoding JSON through an Express API

Recently, I have been teaching myself about Node.js and Express, specifically focusing on returning JSON results from a Google Maps Geocoding API request. I have managed to make it work using the `require` module, but I am determined to understand where I ...

The Vue2 @click event does not function properly when using v-html within a different component

I currently have a sign up form that includes an Alert component for displaying any errors. One of the conditions may prompt a message saying "You already have an account, click here to log in". The error messages are passed as props to the "Alert" compon ...

The trigger for the newly loaded AJAX data failed to activate

I am facing an issue with loading data via ajax and handling file uploads. I am trying to trigger a click event when clicking on the submit button, but it is not working as expected. Can someone please help me with this? Here is the code snippet that I ...

Transferring an array in JavaScript to a different page without relying on PHP

Is there a way to transfer data stored in a JavaScript array to another page without using server-side scripting like PHP? Can this be achieved with JS, jQuery, or similar tools? My goal is to access the array in my JS script on the destination page. Appr ...

Transforming dynamic tables into JSON format

Whenever a user adds a new row to the dynamic table to input customer information, I require the data to be submitted in JSON format upon clicking the submit button. HTML <table class="table table-bordered table-hover" id="driver"> ...

Leveraging AJAX for transmitting form information to a php script without relying on jQuery

I want to explore AJAX by implementing a basic form data submission to a php script and database. For educational purposes, I've reached a standstill after hitting the "Create Profile" button with no action. Could someone spot any syntax or structural ...

The age-old debate: Deciding between JavaScript's touchend and

Currently delving into some JavaScript UI work, focusing on optimizing touch events like 'touchend' for smoother interactions on touch-enabled devices. Nonetheless, encountering a few perplexing logical dilemmas... A common practice I've no ...

React + Redux triggering excessive re-renders of mapped components when making additional API calls

I am in the process of developing a website similar to MyAnimeList(MAL) using Jikan, an unofficial MAL API integrated with React and Redux. I want to replicate the promotional video section on the home page that showcases thumbnails of popular anime videos ...

Accessing a React component by ref before it has been rendered for the first time

In my component, I have a set of links with an animated line underneath the active link using position: absolute. Before I can position the underline correctly, I need to determine the offset().left value of the active link. The challenge is that before ...

Using Javascript to organize an array of objects based on a specific condition

Having an array of objects structured as follows: obj = [{'name': 'Tom', 'age': 17, 'gender': 'male', 'color':'red', 'position':3}, {'name': 'Sam', ...

When using Next.js to load a client-side library, the component undergoes multiple re-renderings as the state of the parent component changes

On the client side, I am loading the emoji-mart library because it requires the window object. After loading the library, a component is returned. However, when the component is called, it is initially rendered twice and then multiple times as the parent ...

Achieving vertical center alignment for the label and btn-group in Bootstrap

Is it possible to align other elements with the Bootstrap btn-group? <div class="btn-toolbar text-center"> <div class="pull-left"> <span class="glyphicon glyphicon-envelope " style="font-size:1.5em;"></span> < ...

Managing multiple Sequelize DB connections in NestJS: A guide

I recently came across the example in the NestJS documentation regarding setting up a Sequelize DB connection. I'm curious about how to connect to multiple databases using Sequelize and TypeScript with NestJS. Can anyone provide guidance on this? ...

How can I make col-8 and col-4 display next to each other?

Here is the code snippet I recently submitted: <section class="main-container"> <div class="grid-row no-gutters"> <div class="column-8"> <img class="full-width-img& ...

Utilizing an NPM package in your project

Trying to incorporate a node module called "tagify" into my node.js application has been challenging. Following the instructions in the package's readme file (https://www.npmjs.com/package/@yaireo/tagify#installation), I executed the setup steps as ou ...

The compatibility of IE9 with tables and the use of display: block

When optimizing my site for low-width mobile devices, I adjust the display property of various table elements such as tr, td, and th to block in order to stack them vertically. This technique helps wide tables to show all their content without overflowing ...