The perfect way to achieve page scrolling (Scroll) effect with jQuery

巴扎黑
Release: 2017-06-29 09:39:06
Original
1604 people have browsed it

Many bloggers have written/reprinted the method of usingjQueryto achieve the page scrolling (Scroll) effect in the past, but most of the methods found so far have a small bug under Opera: use jump directly And the screen flickers.

Today, the super low-key expert Willin shared a perfect method to solve the bug of jQuery implementing scrolling effect under Opera. I thendebug+applied it to my current theme and it has been tested. It's perfect, I posted the code to illustrate it.

Because I don’t know much about js and jQuery is only superficial. I can’t explain the principle clearly. I can only explain the modification method.

Demo: Click "Δ" at the bottom of the current topic zOM/"x comments" "" below the title of the article page Leave a comment

Assumption: The top id of your topic isheader, and the bottom “return to top” id is top

jQuery code is as follows:

document$ windowopera ? documentcompatMode ? $ $ $ $ scrollTop $top false
Copy after login

Instructions: Seecomments directly

$('#top ').click(function(){...}); This is the basic code for scrolling. You can adapt it according to your own situation, that is, draw inferences from one example. For example, since you can return to the top, you can scroll to the bottom or scroll to a certain point. An id, scroll to the middle...

Then I will post an example of scrolling to the "comment box":

The premise of the example is: there is a below the article title "Add comment", the original html is as follows

Copy after login

(Note: #respond is the id of the comment box)

Then $('#top').click(function(){.. .}); This code becomes as follows:

$ scrollTop $top false
Copy after login

That’s it, isn’t it simple? Some friends say the principle, go and learn jQ

For more methods, go to Willin's "Several Methods of Page Scroll"

Statement:This article adopts BY-NC- Authorized under SA agreement | ZWWoOoOo
Please indicate that the reprint is from "The perfect method to achieve page scrolling (Scroll) effect with jQuery"

Read the full text
Category:JavascriptView comments

The above is the detailed content of The perfect way to achieve page scrolling (Scroll) effect with jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!