When the div element reaches the top of the page, it sticks to the top and is only displayed when the user

In the center of a full-screen hero section, there is a form. When it reaches the top, its position becomes fixed and additional classes are added through a script - such as shrinking its height and adding a background.

What I aim to achieve is for the form to hide when it reaches the bottom of the section#hero and then display again when the user scrolls up.

If you visit , you can see that their search container behaves exactly how I want my sign-up form in the landing page to behave.

Thank you in advance!

Here is the section containing the form:

$(function() {
  // Check the initial Poistion of the Sticky Header
  var stickyHeaderTop = $('#grab').offset().top;
  var Innerwidth = window.innerWidth;

  $(window).scroll(function() {
    if (Innerwidth >= 767) {
      if ($(window).scrollTop() > stickyHeaderTop) {
        $('#grab').css({
          position: 'fixed',
          top: '0',
          left: '0',
          width: '100%',
          background: '#363451',
          paddingBottom: '15px'
        });
        $('form#signUp').css({
          marginTop: '15px'
        });
        $('form#signUp input').css({
          height: '45px',
          fontSize: '14px'
        });
        $('form#signUp button').css({
          height: '45px'
        });
      } else {
        $('#grab').css({
          position: 'relative',
          background: 'none'
        });
        $('form#signUp').css({
          marginTop: '25px'
        });
        $('form#signUp input').css({
          height: '65px',
          fontSize: '16px'
        });
        $('form#signUp button').css({
          height: '65px'
        });
      }
    }
  });
});

Answer №1

Here is a way to achieve this functionality:

if($(window).scrollTop() + $(window).height() == $(document).height()) {

    $('#grab').slideUp();

}else{

    $('#grab').slideDown();

}

Note: I made changes like adding a higher z-index to your #grab container and removing the height:100vh; from hero.

https://jsfiddle.net/u5b514wu/

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 best way to target the nth-child() of a slotted element within a web component that utilizes multiple uniquely named slots?

I am struggling to select the second slotted item in a specific slot using slot[name=foo]::slotted(:nth-child(2)){, but it's not behaving as I anticipated. Even though the first foo slot is styled with green, the second one doesn't follow suit. ...

How can I use jQuery to customize the appearance of a select element, including the arrow, dropdown menu, and

Could you help me with something related to programming? Have you ever tried customizing the select element? I've come across information stating that due to it being OS specific, styling it without jquery using simple css is not feasible. I&apo ...

Develop a React npm package with essential dependencies included

I have been working on developing a UI library using React ts. As part of this project, I integrated an external library called draft-js into the package. However, when I attempt to implement my library in another project, I keep encountering errors. Despi ...

Tips for boosting the efficiency of replaceWith on Internet Explorer 11

When rendering an array of data in a table element, there is a need for the table to be updated with new data as it can be filtered dynamically. However, I have encountered a performance issue specifically on IE11 when trying to render 1700 data entries us ...

menu fails to expand when clicked in mobile view

Could someone please help me troubleshoot why the menu icon is not expanding in mobile view? I'm not sure what I did wrong. Here is the link for reference: Snippet of HTML: <nav class="navbar navbar-default navbar-fixed-top" role="navigation"> ...

The jQuery change event is not triggered for <input type="file"> when a file is dropped on the label

I am currently developing a drag and drop file uploader that can be activated by either clicking the label or dragging a file onto the label. The input field includes a jQuery on change event that is triggered when a file is selected. However, it only see ...

Tips for overlaying text onto a MaterialUI icon

https://i.stack.imgur.com/cFr5Y.pngI am currently working on a project that requires me to overlay a number on top of an icon. Specifically, I am utilizing the MaterialUI ModeComment icon and attempting to display text over it. Despite trying the following ...

The value of element.scrollTop is consistently zero

Why does the scrollTop position of an element always return 0? How can I correct this issue? JSFiddle var inner = document.getElementById('inner'); window.addEventListener('scroll', function() { console.log(inner.scrollTop); }) # ...

Error Alert: The combination of React and Redux-router is causing an unexpected issue. The reducer is expected to be a

Whenever I make a coding mistake and encounter a runtime error, the error reporting is not very helpful. For example, when I mistakenly typed Date() instead of new Date(), the error message I received was... Uncaught Error: Expected the reducer to be a fu ...

Learn the step-by-step process of cropping and zooming an image using the react-image-crop

I am looking to implement zooming and cropping functionality for an image using react-image-crop instead of react-easy-crop. Currently, the cropping does not take into account the zoom level set by ReactCrop's scale property. I want to be able to zo ...

Interactive text that changes when hovered over in an HTML document

My table contains text and I have implemented code that displays a small text when hovering over it. I would like the entire column to trigger the text display on hover, ideally in a larger size. Any suggestions on how to achieve this? ...

Unleashing the power of dynamic column width in Material UI Grid

Is it possible to dynamically change the column width for grid items within the same container in material UI grid? Sometimes I have 2 grid items that need to display in the same row, and other times I have 4 grid items that I want to appear in the same r ...

Is Vue js converting nested objects into strings before returning them?

There is an object in my code var user = { name:"test", number:"9666-0503", details:{ test:"cannot_access_this", second_field:"nope_no_go" } } A call to a Vue JS action is being made [TYPES.FETCH_USER]({ ...

Tips for correctly implementing CORS (Cross-Origin Resource Sharing)

Is there a way to securely access a resource from a third-party domain using XML HTTP Requests (XHR, AJAX)? I have set up CORS on both the target and origin sides with the following configuration: Access-Control-Allow-Origin: http://www.example.com, http ...

Implementing recursive functions in jQuery selectors

I have 11 different dashboard elements that I need to display in a specific order. Here is the HTML code snippet I am currently using: <button type="button" class="btn btn-default" ng-model="settings.isBigger" ng-disabled="false" btn-checkbox btn-ch ...

Showing navigation items in Vuejs based on authentication status

In my current project, I am developing a Single Page Application (SPA) using vuejs with vuetify and integrating authentication via a laravel/passport API. The challenge I'm facing is related to conditional rendering of navigation icons based on user a ...

Launching an external JavaScript from within a separate JavaScript file

I'm in the process of developing a virtual 'directory' for various locations in my city to assist fellow students. Here's the concept: On a map, I've pinned all the locations Clicking on these pins triggers a JavaScript funct ...

VueJS does not support certain characters in its JavaScript replace function

In my current situation, I am utilizing the replace method in the following manner: <code v-html="'/<try>/'.replace(/(?:\r\n|\r|\n)/g, 'testing')"></code> As I work with a longer string t ...

Utilizing a dynamic value in an Angular directive

For my latest project, I am working on developing a basic JSON pretty-printer directive using angular.js. Here is the code snippet I have so far: (function(_name) { function prettyJson() { return { restrict: 'E', ...

Guide: Implementing material-ui theme with redux in gatsby

I'm currently utilizing the material-ui theme in conjunction with redux-toolkit within a gatsby project. This is my theme.ts file: import { createMuiTheme } from "@material-ui/core"; import { useSelector } from "react-redux"; import { State } from ". ...