Get the App
SLTechnology News&Howtos  ›  Database  › 

How to achieve full-screen scrolling effect similar to fullpage plug-in by jQuery

Shulou Source: shulou.com Published: 2022-05-31 18:11:22 10月02日 Update

This article mainly explains the "jQuery how to achieve full-screen scrolling effect similar to the fullpage plug-in", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "jQuery how to achieve a full-screen scrolling effect similar to the fullpage plug-in" bar!

Combined with the ideas on the Internet, coupled with the code I made before, the code has these functions:

1. The contents of the head and tail can be scrolled without scrolling, as long as they are scrolled in the middle.

two。 Support the animation trigger of the previous screen and the next screen

3. Support the next page and previous page navigation jump

4. Support mini navigation display and jump to a page

HTML Code:

Header

Page1

Page2

Page3

Page4

next page

Footer

When setting CSS, you need to note that there are two parent class elements, and the outermost one should be set beyond the height of hiding.

.doc {height:640px;position:relative;overflow:hidden}

.main {position:relative}

.doc .page {position:absolute;height:100%;width:100%;top:100%}

.doc.done .page {position:static;top:0}

JS code, note that the scrolling compatible code uses the jQuery plug-in jquery-mousewheel. Don't miss this plug-in.

JS:

$(function () {)

Var onScroll = false

CurIndex = 0

Len = $(".doc .page") .length

Var winHeight = $(window) .height ()

/ / var boxHeight = winHeight- 60 > 640? WinHeight-60: 640; / / when you need to display all the content, you need to give the outer layer a fixed height to ensure that all the content can be seen.

Var boxHeight = winHeight-60

Var toPage = function (curIndex) {

OnScroll = true

Var now =-curIndex * boxHeight

$(".page") .eq (curIndex) .addClass ("current") .siblings (".page") .removeClass ("current")

$(".page-nav I") .eq (curIndex) .addClass ("current") .siblings ("I") .removeClass ("current")

(".main") .animate ({

Top: now + "px"

}, 1000 times function () {

OnScroll = false

});

}

$(".doc") .css ("height", boxHeight)

$(".main") .css ("height", boxHeight * len)

(".page") .css ("height", boxHeight)

$(".doc") .addClass ("done")

Var pageNext = function () {

If (curIndex = = len-1) return

CurIndex++

ToPage (curIndex)

}

Var pagePrev = function () {

If (curIndex = = 0) return

CurIndex--

ToPage (curIndex)

}

(".doc") .on ("mousewheel", function (e, I) {

If (onScroll) return

If (I <-.2) {

/ / Scroll down

PageNext ()

} else {

/ / scroll up

PagePrev ()

}

});

$('.nextPage') .on ('click',function () {

If (onScroll) return

PageNext ()

});

$('.page-nav i') .on (' click',function () {

If (onScroll) return

Var index = $(this) .index ()

ToPage (index)

})

});

Thank you for reading, the above is the content of "jQuery how to achieve full-screen scrolling effect similar to fullpage plug-in". After the study of this article, I believe you have a deeper understanding of how jQuery achieves full-screen scrolling effect similar to fullpage plug-in, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Plug-ins code content effects learning support ideas height previous one navigation no two elements functions animation outer layer head that is tail situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info macOS OPPO Reno MariaDB