Element Reveal at Scrolling down within a Range

Thames International

I have coded using jquery and css to reveal my contact form while I scrolling down the page. But I tried to set a range of element display while scrolling. At this time I have only setup the scrolling down and hiding part. Need to develop code for Display this object within 200px - 1024px range only.

Anyone have idea for this. Please send me an answer.

Please see this animated gif: https://gph.is/2RpQrOp OR https://ibb.co/6y7wCmK

var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
  var currentScrollPos = window.pageYOffset;
  if (1600 > currentScrollPos) {
    document.getElementById("sticky").style.top = "200px";
  } else {
    document.getElementById("sticky").style.top = "-1000px";
  }
  prevScrollpos = currentScrollPos;
}
/* Test contact-sticky*/

.sticky {
  position: fixed;
  transition: top 0.3s;
  top: -1000px;
  left: 827px;
  right: 46px;
  background-color: #ebc11d;
  padding: 50px;
  font-size: 14px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
<p class="sticky">Contact form</p>

Prajwal

There are few issues with your markup and css.

  1. You are expecting ID to be there in contact form. document.getElementById("sticky") But there isn't one. Either add ID there or get it from class using getElementByClassName
  2. Have proper offset defined. For this snippet to work, I had to set 200 as offset. If you are planning to support multiple resolution, then it is better to get complete document length and then subtract some 200px and use it as offset.
  3. Do not have conflicting changes between in-line and stylesheet styles. document.getElementById("sticky").style.top changes in-line styling where as top: -1000px; is defined from stylesheet.

var prevScrollpos = window.pageYOffset;
var currentScrollPos = window.pageYOffset;
if (10 < currentScrollPos && 210 > currentScrollPos) {
    document.getElementById("sticky").style.top = "0px";
  } else {
    document.getElementById("sticky").style.top = "-1000px";
  }
window.onscroll = function() {
  currentScrollPos = window.pageYOffset;
  if (10 < currentScrollPos && 210 > currentScrollPos) {
    document.getElementById("sticky").style.top = "000px";
  } else {
    document.getElementById("sticky").style.top = "-1000px";
  }
  prevScrollpos = currentScrollPos;
}
/* Test contact-sticky*/

.sticky {
  position: fixed;
  transition: top 0.3s;
  background-color: #ebc11d;
  padding: 50px;
  font-size: 14px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<p class="sticky" id="sticky">Contact form</p>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to reveal element by scrolling?

iphone scroll down page with horizontal scrolling element

Selenium: Scrolling down until the 'style' of an element changes

Having trouble scrolling down to element in Selenium, python

Count element within a range in panda

Animate scrolling to top of element within an overflow div

Issue scrolling down selectInput within a draggable absolute pane

Cause arrow to fade out when scrolling down within div

Make div appear while scrolling within a specific range on web page

Screen which element is within a range in R

How to get element within range for nested list

<a> element styled button is scrolling down my web page

Bootstrap affix - Cant manage to hide image element when scrolling down

Reveal Div as user scrolls down

CSS Mask Reveal Element

Minesweeper Reveal Element Python

find first element within a range not included in another range

How to scroll to an element WITHIN a div, without scrolling entire page (no JQuery)?

Sticky Navbar scrolls away when scrolling within main element

Reveal component only on the clicked element

Reveal image on hovered SVG element

Javascript validation followed by reveal of an element

Reveal hidden span element Javascript

Python - Find an element in a List of Lists which is within a given range

Method to get the count of an element in an array within specified range

find difference between max and min element within a range of an array

Linq repeat every nth element for a given range within a List<T>

Multiple slide down on click reveal div

Scrollview not scrolling down completely