Full page occupied by image, not just a banner separator

I'm having trouble creating a scrolling banner that blurs as you scroll. Whenever I attempt it, the image takes up the entire page background (it's positioned behind all elements but still fills the entire page). I actually want the image to be in a top section like a typical banner.

Using HTML/CSS

<div id="banner-container" object="banner" style="height: 250px; width: 100%">
<div class="banner" style="position: fixed;   background-position: center; -webkit-background-size: cover; top: 0; bottom: 0; left: 0; right: 0; z-index: -1; background-image:url('http://s6.postimg.org/d7gcsqvdt/image.jpg')"></div>
<div class="banner-blurred" style="opacity: 0; background-image:url('https://d262ilb51hltx0.cloudfront.net/fit/c/1600/1280/gradv/29/81/40/darken/50/blur/50/0*I7mXgSon9oco-rim.jpeg')"></div>

Implementing JavaScript

$(window).scroll(function() {
    var s = $(window).scrollTop(),
    opacityVal = (s / 150.0);
    $('.banner-blurred').css('opacity', opacityVal);
});

Answer №1

If you're looking to achieve a specific effect, consider using the following code snippet:

$(window).scroll(function() {
            var scrollPos = $(window).scrollTop();
            if (scrollPos >= 100){
              $('.banner').css({'bottom':'auto', 'height' : '250px'});
            } else {
              $('.banner').css({'bottom':'0', 'height' : 'auto'});
            }
            opacityVal = (scrollPos / 150.0);
            $('.banner-blurred').css('opacity', opacityVal);
});

Based on your description (where an image fills the entire page behind all elements but you want it in a top banner), the .banner class div should remain fixed in position as id="banner-container". You can achieve this by setting the .banner class to be positioned fixed with bottom: 0. Make sure to change it to auto and add a height of 250px to match id="banner-container". The provided code will adjust the .banner css after scrolling past 100px.

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

How to reference color variables from code behind in ASP and use them in CSS files

I have a total of 3 files dedicated to my Login-Screen: Login.aspx, Login.aspx.cs, and LoginStyle.css Upon the execution of the Page_Load method, I retrieve various data from the current system, including the theme-color represented as a string (e.g., #00 ...

Issue 1054 - The variable being used as a field in the WHERE clause is being interpreted as a column

While attempting to update a mysql database, I encountered an error where the variable 'id', which is used as a field in the WHERE clause, is being interpreted as a column name. Am I misreading this? What needs to be corrected in order for this q ...

Challenges in decoding %20 characters in URLs

In my experience, I've come across a helpful thread that explains how to create permalinks or pass string values via a URL in a very practical manner: Original Thread However, it seems that the above-mentioned thread does not address decoding white ...

Encase your Angular application within a jQuery function

I am currently developing an AngularJS application within a jQuery-based system. To properly initiate each app, I need to use the following code snippet: How can I integrate this with my existing AngularJS code? I attempted to enclose my entire Angular a ...

Problem with Firefox full screen slider

Welcome to my website where I have created a full-screen slider for you to enjoy. If you'd like to check it out, just click on the website link. The slider functions perfectly on Chrome and IE, but unfortunately on Firefox, it only shows half of the ...

Canvg | Is there a way to customize canvas elements while converting from SVG?

Recently, I encountered an issue with styling SVG graphics dynamically generated from data. The SVG graphic appears like this: https://i.sstatic.net/xvIpE.png To address the problem, I turned to Canvg in hopes of converting the SVG into an image or PDF us ...

What is the rationale behind utilizing both 'format.js' and 'format.json' in the Rails Edge Guides AJAX example?

Within the section dedicated to working with Javascript in Rails Edge Guides, an illustration is presented illustrating how a 'create' action can be structured within a 'User' controller for the purpose of incorporating AJAX into the cr ...

How to prevent image rotation when applying skew?

I am attempting to slice a small element out of an image using the skew function. However, when applying skew, the image appears distorted and broken. I would like to maintain the image's original orientation without rotation. This is the code snipp ...

What causes a delay in the start of a child process in Node.js?

I am in the process of developing a global node command line program that can execute any console command I provide it with in a new console window, whether on a Windows or Unix system. The goal is for the program to exit after it spawns its process so tha ...

Gradually fade with JavaScript

My JavaScript code below is used to recursively reload a specific DIV with the results of a data query. The issue I'm facing is that each time the DIV, identified by id="outPut", is reloaded, all the data fades in and out due to the fadeTo function. ...

Exploring the integration of Mariadb COLUMN_JSON data in JavaScript

I am encountering difficulties while attempting to access COLUMN_JSON data in JavaScript. I referred to a MariaDB JSON example and inserted it into a table with the following query: UPDATE myTable SET myJsonColumn = COLUMN_CREATE('color', ' ...

Is it possible to adjust the block size for infinite scrolling in Ag-Grid?

Is there a way to adjust the block size in the scenario where the row model is set to "infinite" and a datasource is specified? For instance, when the getRows() function of the datasource is called, is it possible to define the startRow and/or endRow? The ...

Utilize Javascript to interpret a structure that resembles JSON

My data resembles JSON, with columns and names listed: columns: [ { allowNull: false, autoEnterSubType: 0, autoEnterType: 2, creationOrderIndex: 0, dataType: 4, databaseSequenceName: "seq_admintraties_adminratie_id", flag ...

Using CSS grid for optimal responsive design

Today I delved into the world of CSS grid and instantly saw its potential in creating stunning layouts. However, one aspect that has me perplexed is how to adapt the grid for mobile devices. Below is an example that functions perfectly on a desktop screen ...

Enable drawing on a div element and synchronizing it across multiple divs using Javascript and HTML5

I am embarking on a project to create a website that allows users to doodle on an element and share it with others viewing the page using ajax - essentially a small-scale whiteboard feature. While I have a good grasp of HTML, CSS, Javascript (specificall ...

Unable to locate the iframe in the test scenario

I encountered this particular test case: Select Frame id=coach_frame63454108.cf1 Wait Until Element Is Visible ${ap.gui.header.appname} Page Should Contain Element ${ap.gui.header.appname} Page Should Contain Element ${ap.gui.hea ...

Triggering of NVD3 Angular Directive callback occurring prematurely

Lately, I've delved into utilizing NVD3's impressive angular directives for crafting D3 charts. They certainly have a sleek design. However, I'm encountering numerous challenges with callbacks. While callbacks function smoothly when incorpor ...

Laravel method to send back JSON error messages through the use of an "error" object in the response

My aim is to utilize the "Bootstrap File-input" plugin for JQuery to facilitate file uploads via AJAX. This plugin expects error messages to be received in a JSON key labeled "error" as shown below: {error: 'You are not allowed to upload such a file. ...

Utilizing Cowboy as the HTTP web server for Express JS

Many websites are utilizing Cowboy as the HTTP Web server and Express JS as the Web application server. They typically have their HTTP header set to Cowboy for the server, with the X-Powered-By HTTP header indicating Express. One example is This setup rai ...

Tips for creating a web page layout that minimizes formatting issues when copying and pasting into Microsoft Word

As I work on developing a web application, I am aiming for users to have the ability to easily copy parts of the page and paste them into MS Word with minimal loss of HTML formatting. One scenario involves allowing users to copy just a table from the page ...