current position:Home>Two easy-to-use animation JS that make the page move
Two easy-to-use animation JS that make the page move
2021-08-27 12:56:40 【78904) sauce:】
scrollReveal.js
and WOW.js equally ,scrollReveal.js Is also a page scrolling animation JavaScript, It makes the page more interesting , More attractive to users . The difference is WOW.js The animation is played only once , and scrollReveal.js Your animation can be played once or indefinitely ;WOW.js rely on animate.css, and scrollReveal.js Do not rely on any other files .
although scrollReveal.js Do not rely on animate.css, But its animation is also used CSS3 Created , So it doesn't support IE10 The following browsers .
The basic method
1、 The introduction of the file
<script src="js/scrollReveal.js"></script>
Copy code
2、HTML
<div data-scroll-reveal>dowebok.com</div>
Copy code
You must add... To the element data-scroll-reveal attribute , After adding, the default animation effect will be executed , You can also customize the properties to display different animation effects , Such as :
<div data-scroll-reveal="enter left and move 50px over 1.33s">dowebok.com</div>
<div data-scroll-reveal="enter from the bottom after 1s">Hello world!</div>
<div data-scroll-reveal="wait 2.5s and then ease-in-out 100px">iPhone 6</div>
Copy code
3、JavaScript
window.scrollReveal = new scrollReveal();
// perhaps ,elem Is the parent element of any level of the animation element
window.scrollReveal2 = new scrollReveal({elem: document.getElementById('srcontainer')});
Copy code
data-scroll-reveal attribute
It says you can customize data-scroll-reveal attribute , Let's take a look at the keywords and values of this attribute ( Optional ).
enter
- explain : Animation start direction
- value : top | right | bottom | left
move
- explain : Animation execution distance
- value : Numbers , With px In units of
over
- explain : Animation duration
- value : Numbers , In seconds
after/wait
- explain : Animation delay time
- value : Numbers , In seconds
fill ( Optional )
Can be in data-scroll-reveal Fill in attribute ( add to ) Some programming like “ sentence ”, Make it more readable ,scrollReveal.js Support the following “ sentence ”:
- from
- the
- and
- then
- but
- with
- ,
That is, you can write like this HTML:
<div data-scroll-reveal="wait 0.3s, then enter left and move 40px over 2s">dowebok.com</div>
<div data-scroll-reveal="enter from the left after 0.3s, move 40px, over 2s">Hello world!</div>
<div data-scroll-reveal="enter left move 40px over 2s after 0.3s">iPhone 6</div>
<div data-scroll-reveal="enter left, move 40px, over 2s, wait 0.3s">I love you</div>
Copy code
Advanced usage
Custom default value
reset Whether the property always loops
You can change scrollReveal.js Default configuration , Such as :
var config = {
after: '0s',
enter: 'bottom',
move: '24px',
over: '0.66s',
easing: 'ease-in-out',
viewportFactor: 0.33,
reset: false,
init: true
};
window.scrollReveal = new scrollReveal(config);
Copy code
dynamic HTML
scrollReveal.init() Method can detect all containing data-scroll-reveal Attribute elements , And initialize , So for dynamically loaded elements , You can do this :
var config = {
enter: 'bottom',
move: '40px',
over: '0.16s',
reset: true,
init: false
};
window.scrollReveal = new scrollReveal(config);
var data = {newElementHtml: '<div data-scroll-reveal>dowebok.com</div>'};
var container = document.getElementById('#container');
container.innerHTML(data.newElementHTML);
scrollReveal.init();
Copy code
WOW.js
Some pages scroll down , Some elements produce small animation effects . Although the animation is relatively small , But it gets your attention . For example, just released iPhone 6 The page of ( see ). If you want your page to be more interesting , Then you can try WOW.js.
WOW.js rely on animate.css, So it supports animate.css As many as 60 A variety of animation effects , Can meet your various needs .
Usage method
1、 The introduction of the file
<link rel="stylesheet" href="css/animate.min.css">
Copy code
2、HTML
<div class="wow slideInLeft"></div>
<div class="wow slideInRight"></div>
Copy code
You can join data-wow-duration( Animation duration ) and data-wow-delay( Animation delay time ) attribute , Such as :
<div class="wow slideInLeft" data-wow-duration="2s" data-wow-delay="5s"></div>
<div class="wow slideInRight" data-wow-offset="10" data-wow-iteration="10"></div>
Copy code
3、JavaScript
new WOW().init();
Copy code
If you need to customize the configuration , It can be used as follows :
var wow = new WOW({
boxClass: 'wow',
animateClass: 'animated',
offset: 0,
mobile: true,
live: true
});
wow.init();
Copy code
To configure
attribute / Method | type | The default value is | explain |
---|---|---|---|
boxClass | character string | ‘wow’ | The elements that need to be animated class |
animateClass | character string | ‘animated’ | animation.css The animation class |
offset | Integers | 0 | How far from the visual area to start the animation |
mobile | Boolean value | true | Whether to perform animation on a mobile device |
live | Boolean value | true | Whether the content loaded asynchronously is valid |
copyright notice
author[78904) sauce:],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210827125637093O.html
The sidebar is recommended
- Crazy blessing! Tencent boss's "million JVM learning notes", real topic of Huawei Java interview 2020-2021
- JS JavaScript how to get the subscript of a value in the array
- One line of code teaches you how to advertise on Tanabata Valentine's Day - Animation 3D photo album (music + text) HTML + CSS + JavaScript
- An article disassembles the pyramid architecture behind the gamefi outbreak
- BEM - a front-end CSS naming methodology
- Another ruthless character fell by 40000, which was "more beautiful" than Passat and maiteng, and didn't lose BMW
- August 23, 2021 Daily: less than three years after its establishment, Google dissolved the health department
- The female doctor of Southeast University is no less beautiful than the female star. She has been married four times, and her personal experience has been controversial
- There are many potential safety hazards in Chinese restaurant. The top of the program recording shed collapses, and the artist will fall down if he is careless
- Introduction to flex flexible layout in CSS -- learning notes
guess what you like
-
CSS learning notes - Flex layout (Ruan Yifeng tutorial summary)
-
Today, let's talk about the arrow function of ES6
-
Zheng Shuang's 30th birthday is deserted. Chen Jia has been sending blessings for ten years. Is it really just forgetting to make friends?
-
Asynchronous solution async await
-
"The story of huiyeji" -- people are always greedy, and fairies should be spotless!
-
Installing Vue devtool for chrome and Firefox
-
Basic usage of JS object
-
1. JavaScript variable promotion mechanism
-
Front end Engineering - scaffold
-
Java SQL Server intelligent fixed asset management, back end + front end + mobile end
Random recommended
- Mediator pattern of JavaScript Design Pattern
- Array de duplication problem solution - Nan recognition problem
- New choice for app development: building mobile applications using Vue native
- Vieira officially terminated his contract and left the team. The national security club sent blessings to him
- Less than 200000 to buy a Ford RV? 2.0T gasoline / diesel power, horizontal bed / longitudinal bed layout can be selected
- We are fearless in epidemic prevention and control -- pay tribute to the front-line workers of epidemic prevention!
- Front end, netty framework tutorial
- The wireless charging of SAIC Roewe rx5 plus is so easy to use!
- Upload and preview pictures with JavaScript, and summarize the most complete mybatis core configuration file
- Ajax foundation - HTTP foundation of interview essential knowledge
- Left hand IRR, right hand NPV, master the password of getting rich