Velocity.js Implementing page scrolling transitions

Source: Internet
Author: User

    • Online Demo 1
    • Online Demo 2
    • Online Demo 3
    • Online Demo 4
    • Online Demo 5
    • Local Downloads
Original link: http://www.gbtags.com/gb/share/5650.htm page scrolling Switch effect

Today introduced a JavaScript small animation plug-in velocity.js, you can easily and efficiently develop a multi-page scrolling transition effect of the site.

Browser support

Velocity.js supports ie8+, Chrome, Firefox and other browsers, and supports Andriod and iOS.

We develop a project that has a large set of related links to the page. Can not do in a page to show them, but also want to be able to effectively read these related content, you can do some interesting effects to help us achieve, through the page scrolling switch effect, can be very effective to create a compelling page.

All the special effects applications are through velocity.js. Velocity.js is an animated jquery plugin that re-implements the jquery $.animate () method to speed up animation switching. Velocity.js is only 7k in size, it contains not only all the functions of $.animate (), but also includes color switch, transform (transform), loop, ease, CSS switch, scroll function, it is jquery, jquery UI, The best combination of CSS transformations in terms of animation. Velocity.js uses the jquery $.queue () method in its internal implementation, so it is smoother than the $.animate (), $.fade (), and $.delay () methods of jquery, and its performance is higher than the animation properties of CSS

All effects cannot be displayed on small terminals, such as mobile phones and smart watches. So it's best to show his functionality on the web, but we've also adapted it for the small terminal to navigate

Points
    • Velocity.js is an animated plugin for jquery, with faster and more efficient animation transitions
    • On May 3, 2014, Julian posted a velocity.js on his github
    • Velocity.js is a small and powerful plugin

Let's look at how it's implemented in detail.

To apply animations and scrolling effects, we have to do this with data-hijacking and data-animation custom settings in the <body> tab.
    1. <body data-hijacking="Off" data-animation="Scaledown">

The above code means that the start animation effect data-animation to scaled down scaledown,data-animation altogether defines 7 different animation effects, respectively, Scaledown,rotate,fixed,gallery, Parallax,opacity,catch. We can apply any kind of effect according to our own needs. And I made 7 pages of the sample code to render its effect separately. Set the data interception property data-hijacking to OFF, you can also set it to on to show its effect. All of the above two attributes are from Velocity.js

DOM structure in HTML

In this structure we want to show 5 different sets of pages, we divide him into five <section>, and also define 2 icon buttons for switching functions.

  1. <body data-hijacking="Off" data-animation="Scaledown">
  2. <section class="cd-section visible">
  3. <div>page scrolling Toggle effect 1
  4. </section>
  5. <section class="Cd-section"><div>
  6. page scrolling Toggle effect 2
  7. </section>
  8. <section class="Cd-section">
  9. <div>page scrolling Toggle Effect 3
  10. </section>
  11. <section class="Cd-section">
  12. <div>page scrolling Toggle effect 4
  13. </section>
  14. <section class="Cd-section">
  15. <div>page scrolling Toggle effect 5
  16. </section>
  17. <nav>
  18. <ul class="Cd-vertical-nav">
  19. <li><a href="#0" class="Cd-prev inactive">Next< /a></li>
  20. <li><a href="#0" class="Cd-next">Prev </a></li>
  21. </ul>
  22. </nav> <!--. Cd-vertical-nav --
  23. </body>
CSS style Additions

By designing each <section> to make it easier for us to view and interact with each other, we can make some corresponding styles according to the requirements.

  1. . CD-section: First-of-type > div {
  2. Background-color: #2b334f;
  3. }
  4. . CD-section:nth-of-type(2) > div {
  5. Background-color: #2e5367;
  6. }
  7. . CD-section:nth-of-type(3) > div {
  8. Background-color: #267481;
  9. }
  10. . CD-section:nth-of-type(4) > div {
  11. Background-color: #fcb052;
  12. }
  13. . CD-section:nth-of-type(5) > div {
  14. Background-color: #f06a59;
  15. }
Event handling

When we set the data interception property data-hijacking to off, all animation effects are scaled proportionally to the relative position of its window. When an animated event is triggered, we will style the current window page to include the scale from small to large, or from large to small. and the relevant transparency changes explained.

Below is a detailed explanation of the following code. First windowheight means that the height of your device window itself is a fixed value, $ (window). ScrollTop () is the height of the scroll bar in the page, which is a range value that is sliding from top to bottom (0~ all page heights), and from the top down (All Page heights ~0). Actualblock.offset (). Top is a set of fixed values, representing each <section> page to the top of the distance is (0, each page height, each page height * *, each page height ... The height of each page depends on the device. After figuring out what these codes mean, we can see the following judgment statement when the offset value is greater than the negative window height, that is, the current page is shifted from the top to the small, and the value of the y-axis is constantly increasing, and the page gradually exits the current view window. When the value of offset is less than the height of the window, that is, when you swipe down from the top, the current page is switched from small to large, and transparency is gradually transparent, and the y-axis value is zero for zooming. Shadow Blur radius change.

  1. Actualblock is the sections we are animation
  2. var offset = $(window). ScrollTop() - actualblock. Offset(). Top,
  3. WindowHeight = $(window). Height();
  4. If( offset >= -windowheight && offset <= 0 ) {
  5. //section entering the viewport
  6. Translatey = (-offset) *+/windowheight;
  7. Scale = 1;
  8. Opacity = 1;
  9. } Else if( offset > 0 && offset <= WindowHeight ) {
  10. //section leaving the viewport
  11. Scale = (1 - ( offset * 0.3/windowheight));
  12. Opacity = ( 1 - ( offset/windowheight) ); /c31>
  13. Translatey = 0;
  14. Boxshadowblur = * (offset/windowheight);
  15. }

After the above event processing, there are two click events, click on the two toggle buttons, the page directly switch, while there are velocity.js event processing functions such as the animation effect Translateup,translatedown,scaledown and other effects.

  1. $. Velocity
  2. . registereffect("Scaledown", {
  3. Defaultduration:
  4. Calls: [
  5. [ { opacity: ' 0 ', scale: ' 0.7 ', boxshadowblur: ' 40px ' }, 1]
  6. ]
  7. });
Conclusion

This is a relatively complex effect, the need for a large number of JS event processing and plug-in function calls, everyone learning is certainly relatively complex. It is recommended to clear logical thinking first, after reading the article, and according to the article points to read the source code. If you are interested in the Velocity.js plugin, you can learn about its other effects. And welcome everyone to interact with me, what do not understand the place welcome the small friends message Oh ~ ~

Original link: http://www.gbtags.com/gb/share/5650.htm

Velocity.js Implementing page scrolling transitions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.