js page scroll to element. Smooth page scrolling up with jQuery. And now in more detail

Here is a huge list of jQuery scroll plugins for your site. Various scrolling tricks came to us from abroad not so long ago and cordoned off a number of modern portals and sites that wanted to stand out. Working on vertical scrolling could well improve conversions and undoubtedly the user experience. Thanks to interesting JS + CSS3 approaches, you can improve the interface of your site. If you add a little imagination, you can get something unique for your site from any plugin. After all, every site is trying to stand out from the gray mass different ways. Thanks to scrolling, some pages can be transferred to a page with an implemented plugin, which will improve the receipt important information user. This technology best suited for various portfolios or product demonstrations, etc.

Let's go straight to the point.

Sly

Sly is a JavaScript library for advanced one-way scrolling with element navigation support. It can be used as a simple scroll replacement, as a navigation tool, or as a great navigation and animation interface for parallax sites.

jQuery ScrollPath

This is a plugin for defining custom scroll paths.

windows

Animate Scroll

AnimateScroll is a jQuery plugin that allows you to scroll to any part of the page by simply calling the animatescroll() function with the id or class of the element you want to scroll to.

scrollme

As the page scrolls, ScrollMe can scale, rotate, translate, and change the transparency of elements on the page. It's easy to set up and doesn't require a single line of javascript.

stickup

A simple plugin that "pins" an element to the top of the browser window by scrolling it while always keeping it in view. This plugin works on multi-page sites, but has additional features for layouts with one pager.

block scroll

Block Scroll is a jQuery plugin that turns a set of elements into blocks and displays them one screen at a time. The idea is to break your page into chunks for better presentation and user flow. Scroll lock automatically resizes your page.

Starscroll

Create a div as a background... activate the plugin; scroll animation. The plugin will automatically set the div to work invisible.

scroll deck

scrollocue

Scrollocue is a jQuery plugin for creating a simple autocue/teleprompter system for scrolling lines of text.

scrollorama

Stellar.js

Stellar.js is a jQuery plugin that provides parallax scrolling effects to any scroll element.

super scroll orama

Parallax

Responsive 3d Fold Scroll

jQuery Scrollify

A jQuery plugin that helps you scroll and snap to sections. Compatible with Touch.

vivus.js

Vivus is a lightweight JavaScript class (no dependencies) that allows you to animate SVGs by giving them the ability to draw.

jQuery SlimScroll

slimScroll is a small (4.6KB) jQuery plugin that will transform any div into a scrollable area with a pretty scrollbar.

jQRangeSlider

jQuery pin

Have you ever wanted to pin something to the side of the text? Have you ever needed a thin sticky element that stays in place while you scroll down?

jQuery.Pin is here to help! Insert any element at the top of the container. Easily turn it off for smaller sizes screen, where there is no room for this kind of shenanigans.

Infinite AJAX Scroll

Overscroll

Overscroll is a jQuery and polyfill plugin for Safari mobile scrolling style. It is designed to be used on desktop browsers with the latest version of jQuery.

jQuery.localScroll

Parallax ImageScroll - jQuery Plugin

jQuery and an amd-compatible plugin to create a parallax effect, as shown on spotify.com.

fullPage.js

Lightweight and easy to use plugin for creating full screen scrolling websites (also known as single page websites, landing page), it is also possible to add some horizontal sliders inside the sections of the site.

Parallax.js

Jarallax

Jarallax is an open source JavaScript library. source code which makes it easy to customize the css based on the interaction. Jarallax makes it easy to create a website with parallax scrolling

jInvertScroll

jQuery fullContent.js

jQuery Full Content allows you to completely create websites.

jQuery One Page Scroll

Create a one page scrolling website (iPhone 5S website) with one page scroll plugin.

jQuery Parallax Plugin

jQuery Parallax is a script that simulates the parallax effect as seen on nikebetterworld.com.

jquery.parallax.js

jquery.arbitrary-anchor.js

Portfoliojs

Portfoliojs is a lightweight jQuery gallery plugin for your beautiful horizontal scrolling images that supports desktop, tablet and mobile browsers.

Scrolling Parallax Plugin

Scrolling Parallax is a new jQuery plugin that ties the parallax effect to scrollbars and the mouse wheel. This allows background image or anything else to scroll at a different pace than the web page when the user scrolls. The parallax effect that results is an easy way to create the illusion of depth on your website.

scroll tab

scrolly

scrollr

Separate parallax scrolling library for mobile devices(Android + iOS) and PC. No jQuery. Just plain JavaScript (and some magic).

SMINT

Smint is a simple jQuery plugin that helps with navigation on single page websites.

jQuery custom content scroller

A highly customizable jQuery scroll plugin. Features include a vertical and/or horizontal scrollbar, custom scroll momentum, mousewheel (via the jQuery mousewheel plugin), keyboard support, and touch screen ready to use themes and customization with using CSS, support for RTL direction, option settings for full control of the scroll functions, methods for triggering actions such as scroll, update, destroy, etc.

ScrollUp Bar Plugin

Scroll up plugin (jQuery) hides top panel when scrolling down and showing it when scrolling up. This is especially useful for mobile interfaces to save precious space.

StickyTableHeaders

jQuery panelSnap

isInViewport.js

waterfall

jquery waterfall plugin like Pinterest, huaban.com, faxianla.com

scroller

jQuery.SerialScroll

jscroll

jScroll is a jQuery infinite scrolling plugin written by Philip Klausinsky. Infinite scroll; also known as lazy loading, infinite scrolling, autopyre, infinite pages, etc.

FoldScroll

scrollUp jQuery plugin

ScrollUp is a lightweight jQuery plugin for creating a custom "Scroll Up" feature that will work with any website with ease.

multiScroll.js

Create split pages with two vertical scrollbars. Compatible with mobile phones and devices and old bowsers like IE 8.

Any List Scroller

qpScroll

qpScroll is a jQuery plugin that creates a parallax background for any page or div. It's very easy to set up. It can be added to any existing page without the need to change the HTML marking.

jQuery Stick 'em

Parallax.js

The Parallax Engine responds to the orientation of the smart device. Where there is no gyroscope or motion detection hardware, the cursor position is used instead.

Slinky.js

Slinky.js is a jQuery plugin for creating beautiful scrolling navigation lists with stacking headers.

Infinity.js

Infinity.js is the UITableView for the web: it speeds up scrolling through long lists and keeps your infinite feeds smooth and stable for your users. It is small, time-tested and highly efficient.

Arbitrary Anchor

Waypoints

Waypoints is a library that makes it easy to execute a function whenever you navigate to an element.

jQuery.kinetic

Scrolling Progress Bar

There are two components to this effect. Content and bars. Each content section has an ID that helps calculate the percentage. Each bar has a link to smooth scrolling to that section.

jQuery Smooth Div Scroll

Smooth Div Scroll is a jQuery plugin that scrolls content horizontally to the left or right.

jQuery Story Tale

A simple jQuery plugin extending the animateScroll plugin with single page capabilities.

jQuery Animation Scroll Plugin

jQuery.ScrollTo

Endless Scroll jQuery Plugin

Infinite scrolling (or infinite scrolling) is a popular technique among 2.0 websites such as Google Reader and Live Image Search, where instead of paging through elements using the traditional pagination technique, the page simply keeps loading new elements attached to the end.

I have this input element:

I then have other elements like other text inputs, text fields, etc.

When the user clicks on an input with #subject , the page should scroll to the last element of the page with a nice animation. It should be scroll down and not up.

The last element of the page is a submit button with #submit:

The animation should not be too fast and should be fluid.

I run the latest jQuery version. I prefer not to install any plugin but use default jQuery functions to achieve this.

30 responses

Assuming you have a button with a button id, try this example:

$("#button").click(function() ( $().animate(( scrollTop: $("#elementtoScrollToID").offset().top ), 2000); ));

I wrote this lightweight plugin to make page/element scrolling easier. It is flexible where you could pass in the target element or the given value. Maybe it could be part of the next official release jQuery, what do you think?

Examples of using

$("body").scrollTo("#target"); // Scroll screen to target element $("body").scrollTo(500); // Scroll screen 500 pixels down $("#scrollable").scrollTo(100); // Scroll individual element 100 pixels down

Options:

scrollTarget: An element, string, or number that specifies the desired scroll position.

offsetTop: A number specifying additional spacing above the scroll target.

duration: A string or number that specifies how long the animation will run.

easing: A string indicating which easing function to use for the transition.

complete: A function to call after the animation is complete.

If you have little interest in the effect of smooth scrolling and are just interested in scrolling to a specific element, you don't need some jQuery function for this. Javascript is your business:

So all you have to do is: $("selector").get(0).scrollIntoView();

Get(0) is used because we want to get the element DOM JavaScript, not the JQuery DOM element.

Using this simple script

If($(window.location.hash).length > 0)( $("html, body").animate(( scrollTop: $(window.location.hash).offset().top), 1000); )

Would do in sort that if a hash tag is found in the url, scrollTo will animate the id. If the hash tag is not found, then ignore the script.

  • Section 1
  • Section 2
  • Section 3

Steve and Peter's solution works very well.

But in some cases, you may need to convert the value to an integer. Oddly enough, the return value from $("...").offset().top is sometimes in a float .
Usage: parseInt($("....").offset().top)

For example:

$("#button").click(function() ( $("html, body").animate(( scrollTop: parseInt($("#elementtoScrollToID").offset().top) ), 2000); ) );

A compact version of the "animated" solution.

$.fn.scrollTo = function (speed) ( if (typeof(speed) === "undefined") speed = 1000; $("html, body").animate(( scrollTop: parseInt($(this).offset ().top) ), speed); );

Basic usage: $("#your_element").scrollTo();

If you are only using scroll to the input element, you can use focus() . For example, if you want to scroll to the first visible input:

$(":input:visible").first().focus();

Or the first visible container entry with the .error class:

$(".error:input:visible").first().focus();

In most cases it would be better to use a plugin. Jokes aside. I'm going to . Of course, there are others. But please check if they really avoid the pitfalls you need the plugin for in the first place - not all of them.

I have written about the reasons for using the plugin elsewhere. In a nutshell, the one liner behind most of the answers here

$("html, body").animate(( scrollTop: $target.offset().top ), duration);

Bad UX.

    Animation does not respond to user actions. It executes even if the user clicks, swipes, or tries to scroll.

    If the animation start point is close to the target element, the animation is painfully slow.

    If the target element is near the bottom of the page, it cannot be scrolled to the top of the window. The scroll animation stops abruptly, then in the middle of the movement.

To deal with these issues (and a bunch of others), you can use my plugin, jQuery.scrollable . Then the call will be

$(window).scrollTo(targetPosition);

As for the target position, $target.offset().top does the job in most cases. But be aware that the return value does not take into account the html element (see this demo). If you need the target position to be accurate under all circumstances, it's better to use

TargetPosition = $(window).scrollTop() + $target.getBoundingClientRect().top;

This works even if a border is set with html element.

This is my approach abstracting id and href"s using generic class selector

$(function() ( // Generic selector to be used anywhere $(".js-scroll-to").click(function(e) ( // Get the href dynamically var destination = $(this).attr(" href"); // Prevent href="#" link from changing the URL hash (optional) e.preventDefault(); // Animate scroll to destination $("html, body").animate(( scrollTop: $(destination ).offset().top ), 500); )); ));

Very simple and easy to use custom jQuery plugin. Just add the scroll= attribute to your clickable element and set its value to the selector you want to scroll.

Also: click me. It can be used for any element.

(function($)( $.fn.animateScroll = function()( console.log($("")); $("").click(function()( selector = $($(this).attr( "scroll")); console.log(selector); console.log(selector.offset().top); $("html body").animate((scrollTop: (selector.offset().top)), //- $(window).scrollTop() 1000); )); ) ))(jQuery); // RUN jQuery(document).ready(function($) ( $().animateScroll(); )); // IN HTML EXAMPLE // RUN ONCLICK ON OBJECT WITH ATTRIBUTE SCROLL=".SELECTOR" // Click To Scroll

animations:

// slide to top of the page $(".up").click(function () ( $("html, body").animate(( scrollTop: 0 ), 600); return false; )); // slide page to anchor $(".menutop b").click(function()( //event.preventDefault(); $("html, body").animate(( scrollTop: $($(this. attr("href")).offset().top ), 600); return false; )); // Scroll to class, div $("#button").click(function() ( $("html, body").animate(( scrollTop: $("#target-element").offset().top ), 1000); )); // div background animate $(window).scroll(function () ( var x = $(this).scrollTop(); // freezze div background $(".banner0").css("background-position", " 0px " + x +"px"); // from left to right $(".banner0").css("background-position", x+"px " +"0px"); // from right to left $( ".banner0").css("background-position", -x+"px " +"0px"); // from bottom to top $("#skills").css("background-position", "0px " + -x + "px"); // move background from top to bottom $(".skills1").css("background-position", "0% " + parseInt(-x / 1) + "px" + ", 0% " + parseInt(-x / 1) + "px, center top"); // Show hide mtop menu if (x > 100) ( $(".menu").addClass("menushow"); $(".menu").fadeIn("slow"); $(".menu").animate((opacity: 0.75), 500); ) else ( $(".menu").removeClass("menushow" ); $(".menu").animate((opacity: 1), 500); ) )); // progres bar animation simple $(".bar1").each(function(i) ( var width = $(this).data("width"); $(this).animate(("width" : width + "%" ), 900, function()( // Animation complete )); ));

$("html, body").animate(...) not for me on iphone, browser Chrome browser Chrome.

I needed to set up a target content element on a page.

$("#content"). Animate (...)

Here is what I ended up with

If (navigator.userAgent.match(/(iPod|iPhone|iPad|Android)/)) ( $("#content").animate(( scrollTop: $("#elementtoScrollToID").offset().top ), "slow"); ) else( $("html, body").animate(( scrollTop: $("#elementtoScrollToID").offset().top ), "slow"); )

Whole body content linked with #content div

.... ....

If you want to scroll within the overflow container (instead of the $("html, body") that was listed above), working also with absolute positioning, this is the way to go:

Var elem = $("#myElement"), container = $("#myScrollableContainer"), pos = elem.position().top + container.scrollTop() - container.position().top; container.animate(( scrollTop: pos )

jQuery(document).ready(function($) ( $("a").bind("click.smoothscroll",function (e) ( e.preventDefault(); var target = this.hash, $target = $( target); $("html, body").stop().animate(( "scrollTop": $target.offset().top-40 ), 900, "swing", function () ( window.location.hash = target; )); )); ));

  • Section 1
  • Section 2
  • Section 3

$("html, body").animate((scrollTop: Math.min($(to).offset().top-margintop, //margintop is the margin above the target $("body").scrollHeight-$ ("body").height()) //if the target is at the bottom ), 2000);

To show the full element (with current window size if possible):

var element = $("#some_element"); var elementHeight = element.height(); var windowHeight = $(window).height(); var offset = Math.min(elementHeight, windowHeight) + element.offset().top; $("html, body").animate(( scrollTop: offset ), 500);

I wrote a function general purpose, which scrolls jQuery object, CSS selector, or numeric value.

Usage example:

// scroll to "#target-element": $.scrollTo("#target-element"); // scroll to 80 pixels above first element with class ".invalid": $.scrollTo(".invalid", -80); // scroll a container with id "#my-container" to 300 pixels from its top: $.scrollTo(300, 0, "slow", "#my-container");

Function code:

/** * Scrolls the container to the target position minus the offset * * @param target - the destination to scroll to, can be a jQuery object * jQuery selector, or numeric position * @param offset - the offset in pixels from the target position, e.g. * pass -80 to scroll to 80 pixels above the target * @param speed - the scroll speed in milliseconds, or one of the * strings "fast" or "slow". default: 500 * @param container - a jQuery object or selector for the container to * be scrolled. default: "html, body" */ jQuery.scrollTo = function (target, offset, speed, container) ( if (isNaN(target)) ( if (!(target instanceof jQuery)) target = $(target); target = parseInt(target.offset().top); ) container = container || "html, body"; if (!(container instanceof jQuery)) container = $(container); speed = speed || 500; offset = offset | | 0; container.animate(( scrollTop: target + offset ), speed); );

It has long and already managed to take root among the developers.
So. With the help of the plugins that are presented in this collection, you can create a modern website with excellent dynamics. I think every person who is interested in website development has seen these plugins in action. When scrolling the page, blocks, various elements or text smoothly appear, move out, spin, etc. As practice shows, customers really like these fancy things.
Embedding scrolling effects into a page is not as difficult as it might seem at first glance. All you need is a quality plugin and direct hands. Of course, a novice layout designer may experience difficulties, but once you sit down for a while, understand the principles of work, and the task will seem very simple.
Despite the fact that many people like the animation on the site, you should not overdo it, otherwise you will end up with an overloaded, visually poorly perceived page in which all attention will be riveted on all these “whistles”, and not on the information that needs to be conveyed to the visitor . In addition, the more scripts are connected, the slower the page works. In older browsers, this whole thing may not work at all. Connect effects wisely. Often, a simple smooth, unobtrusive appearance of blocks is enough. This effect gives the page smoothness and dynamics, makes the site alive. In my practice, I had to see a lot of sites with effects without a sense of proportion. It just makes you sick - the only feeling that arises. But, probably, the developers hoped for a “Wow effect”. So. Use everything wisely and in moderation!
All plugins are absolutely free, but I would recommend that you familiarize yourself with the licenses, as in some cases a number of conditions must be met for commercial use.

WOW.js A nice plugin to implement element animation on scroll. It has a lot of animated options for the appearance of blocks and is quite easy to customize. ScrollMagic Another popular plugin with which you can implement complex animation that will be triggered when scrolling the mouse roller. In this case, the plugin allows you to do really complex effects of movement, changing the background on the page and generally deforming shapes. ScrollMagic is often used on promo sites that require a lot of animation.

Scrollme A simple and lightweight plugin with which you can implement spectacular animation when scrolling. You can scale, rotate, move, decrease or increase the transparency of any element.

SuperscrolloramaSuperscrollorama is a powerful but heavy scroll animation plugin. In its arsenal, there are many different settings for animating text, individual DIV elements, including effects.
More detailed information can be found in the documentation for this jQuery plugin.

onScreen is a great plugin that we use a lot in our projects. From allows you to easily and quickly create various effects for the appearance of elements when scrolling the page. The plugin is lightweight and does not load the page.

OnePagejQuery plugin OnePage allows you to split a page into separate screens with a height of 100% and animate the transition through them. It only takes a slight push to start scrolling to the next screen. The same effect was used on the 5s promo site.
There are problems with, as in almost all such plugins. If the text does not fit in height, then it is simply cut off and the scrollbar does not appear.

FSVS Plugin is very similar in functionality to the previous one. Allows you to make a sliding scroll through the screens using css3. Has a similar issue when viewed on phones. Moving through the screens in the form of separate slides is possible both with the help of the mouse roller and by clicking on the dotted side navigation.

jInvertScrolljInvertScroll allows you to create cool horizontal parallax scrolling. At the time when you scroll the mouse roller down, all elements on the page move horizontally, moreover, with different speed, which creates a parallax effect.

WaypointsWaypoints is a jQuery plugin that allows you to show any element when the visitor is at a given point on the page. For example, when a visitor finishes reading an article on the site and approaches the end of the text, an information box pops up on the side of the page with a suggestion to read the next article or a similar article.

Scrollocue An original plugin for specific tasks. Allows you to move around the page by selecting blocks with a simple right-click on the page. With each new click, the element below is highlighted, thereby scrolling the page a little. Keyboard scrolling is also supported.

Scrolling Progress Bar An interesting solution with which you can show the progress of reading the information on the page. It is also possible to break the text into sections and all this will be visually displayed in any place convenient for you on the page.

multiScroll.jsmultiScroll.js is a jQuery plugin, similar to the previous two slider plugins, but with one major difference. If in previous cases it was just flipping the screen, then this one is more like a modern image slider. The screen is divided into two equal parts and the left one is flipped up and the right one is down. Thus, the content is practically torn.
This plugin can be used, for example, to create a portfolio of a photographer or designer. I think visitors will appreciate your site.

browserSwipe.js Another full-screen scrolling plugin that creates a spectacular screen transition. Among the available effects are sliding transition, transition with rotation of the whole screen, scaling and horizontal scrolling across screens. You can combine all the effects on one page.

jQuery.panelSnap Full screen sliding scroll plugin. The plugin does not differ much, at first glance, from the previous ones, but it implements an inner area with scrolling. If we scroll to the end of the inner content, then the transition to the next screen automatically occurs. Theoretically, this is a solution to the problem for adaptive sites. If the inner window is made to full size, on small screens, content that does not fit in height will not be lost.

Recently, types of sites called Landing page- or "landings". They are convenient in that the user receives all the necessary information on one page. Most often, this is information about the product, which describes it from all sides, makes it clear the strengths and advantages and, of course, place an order.

Such sites turn out to be quite long, therefore, for the convenience of moving through them, they often make a navigation menu with links to specific sections. Let's learn how to make it so that when you click on a link, the site smoothly scrolls to the right place.

$("a" ) .click (function () ( var elementClick = $(this ) .attr ("href" ) ; var destination = $(elementClick) .offset () .top ; $("html, body" ) .animate (( scrollTop: destination ) , 600 ) ; return false ; ) ) ; Alternative view

Previously, they did it a little differently - they used the browser definition - $.browser.safari || $.browser.webkit and, depending on the condition, did either $("body").animate() or $("html").animate() . As of version 1.9 of jQuery - $.browser has been removed and will therefore not work. But you can modify the code and get a script like this:

var matched, browser; jQuery.uaMatch = function ( ua ) ( ua = ua.toLowerCase () ; var match = /(chrome)[ \/]([\w.]+)/ .exec ( ua ) || /(webkit)[ \ /]([\w.]+)/ .exec ( ua ) || /(opera)(?:.*version|)[ \/]([\w.]+)/ .exec ( ua ) || /(msie)[\s?]([\w.]+)/ .exec ( ua ) || /(trident)(?:.*? rv:([\w.]+)|)/ .exec ( ua ) || ua.indexOf ("compatible" )< 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/ .exec ( ua ) || ; return { browser: match[ 1 ] || "" , version: match[ 2 ] || "0" } ; } ; matched = jQuery.uaMatch ( navigator.userAgent ) ; //IE 11+ fix (Trident) matched.browser = matched.browser == "trident" ? "msie" : matched.browser ; browser = { } ; if ( matched.browser ) { browser[ matched.browser ] = true ; browser.version = matched.version ; } $("a" ) .click (function () { var elementClick = $(this ) .attr ("href" ) ; var destination = $(elementClick) .offset () .top ; if (browser.chrome || browser.webkit ) { $("body" ) .animate ({ scrollTop: destination } , 600 ) ; } else { $("html" ) .animate ({ scrollTop: destination } , 600 ) ; } return false ; } ) ;

That's all. All success!

Hello friends. In this article, we will analyze the jQuery event when scrolling the page to a specific element. In other words, then. In this example, we will fire an event when the page is scrolled to the footer. Then we will display a small pop-up window with a smooth appearance. And we will also close it on click. What to put in it, decide for yourself, there are a lot of options. Here's what it looks like:

Let's start with perhaps HTML markup and there is nothing unusual here. Everything is quite simple and clear. A large canvas of text, at the bottom of the footer and a block with a button that will appear. Here is the block code:

1 2 3 4 5 6 7 8 9 10 There's a lot of content here... Some text. footer

There's a lot of content here... Some text. footer

Now let's decorate our hidden block and its button:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #block ( display : none ; position : fixed ; top : 15px ; right : 15px ; color : #fff ; background : #4CAF50 ; padding : 10px ; border-radius : 5px ; width : 200px ; box-shadow : 0 13px 20px -5px #3a3a3a ; font-family : Arial; text-align : center ; ) .btn( background : #FF9800 ; border : 2px solid #795548 ; color : #fff ; border-radius : 5px ; cursor : pointer ; padding : 5px 10px ; margin-top : 10px ; font-weight : bold ; )

#block( display: none; position: fixed; top: 15px; right: 15px; color: #fff; background: #4CAF50; padding: 10px; border-radius: 5px; width: 200px; box-shadow: 0 13px 20px -5px #3a3a3a; font-family: Arial; text-align: center; ) .btn( background: #FF9800; border: 2px solid #795548; color: #fff; border-radius: 5px; cursor: pointer; padding: 5px 10px; margin-top: 10px; font-weight: bold; )

Now let's deal directly with what is called scroll to element. Still English language necessary for the developer. Include jQuery as standard. I will do it via CDN as it will be the most up to date version.

And then the script code itself, which will create magic on the page:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 $(document).ready (function () ( var $element = $(".footer" ) ; let counter = 0 ; $(window) .scroll (function () ( var scroll = $(window) .scrollTop () + $(window) .height () ;//If scroll to the end of the element //var offset = $element.offset().top + $element.height(); //If scroll to the beginning of the element var offset = $element .offset () .top if (scroll > offset && counter == 0 ) ( $("#block" ) .fadeIn (500 ) ; counter = 1 ; ) ) ) ; $(".btn" ) .click (function () ( $("#block" ) .slideUp () ; ) ) ; ) ) ;

$(document).ready(function()( var $element = $(".footer"); let counter = 0; $(window).scroll(function() ( var scroll = $(window).scrollTop() + $(window).height(); //If scroll to the end of the element //var offset = $element.offset().top + $element.height(); //If scroll to the beginning of the element var offset = $element .offset().top if (scroll > offset && counter == 0) ( $("#block").fadeIn(500); counter = 1; ) )); $(".btn").click(function ()( $("#block").slideUp(); )); ));

By default, the event fires as soon as the beginning of the element, in this case the footer, comes into view, but you can change the value by uncommenting line 7 and then the function will fire when the scroll reaches the end of the element.

like this in a tricky way you can show site visitors your unique offer and by adding goals in the metric, track its conversion.