Home Web Front-end H5 Tutorial AlloyTouch full-screen scrolling plug-in creates a smooth H5 page in 30 seconds

AlloyTouch full-screen scrolling plug-in creates a smooth H5 page in 30 seconds

Jan 11, 2017 am 09:42 AM

Usage posture

When designing a full-screen scrolling plug-in, I hope that developers will almost:

Quickly generate exquisite H5 without writing any scripts

Support PC scroll wheel and mobile touch

Cool transition effects

Flexible timeline management

Everything is configurable

But no scripting Surely there is no flexibility? ! no. Not only can you configure some parameters in HTML, you can also inject some logic through the callback function of the plug-in. Let’s take the partial HTML of the example you saw above by scanning the code to analyze the usage posture of AlloyTouch.FullPage:

<div id="fullpage">
    <div>
      <div>
        <div class="animated" data-show="bounceInLeft" data-hide="bounceOutLeft">AlloyTouch Introduction</div>
        <div class="animated" data-delay="500" data-show="bounceInUp" data-hide="zoomOut"><img src="asset/alloytouch.png"></div>
        <div class="animated" data-delay="1200" data-show="bounceIn" data-hide="bounceOut">By AlloyTeam</div>
      </div>
    </div>
     
    <div>
      <div>
        <div class="animated" data-delay="100" data-show="flipInY" data-hide="flipOutY" >Powerful Features</div>
        <div class="animated" data-delay="400" data-show="zoomIn" data-hide="zoomOut"><img src="asset/power.png"></div>
      </div>
    </div>
    ...
    ...
    ...
 </div>
Copy after login

Note that the above is only part of the HTML, and I have combined some with the plug-in Configuration-independent HTML has been removed. Let’s analyze them one by one:

class="animated" conforms to the convention of animate.css. Adding this class means there will be animation.

data-delay represents how long the marked DOM element will wait before starting to play animation after scrolling to the page. The default value is 0 if the developer does not mark it.

data-show represents the animation type displayed by the marked DOM element

data-hide represents the hidden animation type of the marked DOM element (this is usually invisible to the user, but for show Time smoothing, generally set to the opposite type of data-show)

So much, so many configurations, so many configurations! ! Simple enough! !

Of course you need to initialize it in js:

new AlloyTouch.FullPage("#fullpage",{
    animationEnd:function () {
     
    },
    leavePage: function (index) {
      console.log("leave"+index)
    },
    beginToPage: function (index) {
      console.log("to"+index);
      pb.to(index / (this.length-1));
    }
  });
Copy after login

animationEnd is the callback function after the scroll ends

leavePage represents leaving a certain page Callback function

beginToPage represents the callback function that intends to go to a certain page.

The pb above is used to set the progress of nav or progress. This can be ignored for now. If necessary, users can encapsulate any progress bar component themselves.

Principle Analysis

Here we mainly extract the core code of AlloyTouch.FullPage for analysis:

new AlloyTouch({
  touch: this.parent,
  target: this.parent,
  property: "translateY",
  min: (1 - this.length) * this.stepHeight,
  max: 0,
  step: this.stepHeight,
  inertia: false,
  bindSelf : true,
  touchEnd: function (evt, v, index) {
    var step_v = index * this.step * -1;
    var dx = v - step_v;
 
    if (v < this.min) {
      this.to(this.min);
    } else if (v > this.max) {
      this.to(this.max);
    } else if (Math.abs(dx) < 30) {
      this.to(step_v);
    }else if (dx > 0) {
      self.prev();
    } else {
      self.next();
    }
    return false;
  },
  animationEnd: function () {
    option.animationEnd.apply(this,arguments);
    self.moving = false;
  }
});
Copy after login

Here The touch and movement Dom are all fullpage DOM, that is, this.parent

above is scrolling up and down, so the movement attribute is translateY

min, which can be passed through window.innerHeight and the total Calculating the number of pages, this.stepHeight is window.innerHeight

max is obviously 0

step is obviously window.innerHeight, which is this.stepHeight

inertia: false means Disable inertial motion, that is, the user lets go and will not scroll inertly

bindSelf means that touchmove, touchend and touchcancel are all bound to this.parent itself, not to the window. If bindSelf is not set, touchmove, touchend and touchcancel are all bound to window.

We need to explain in detail here. This bindSelf configuration is very useful. For example, a typical application scenario is to solve the problem of AlloyTouch nesting AlloyTouch. For example, in the example you saw by scanning the code above, the Demo with AlloyTouch nested is as follows:

AlloyTouch全屏滚动插件 30秒搞定顺滑H5页

This is actually nested scrolling. Will rolling the inside cause the outside to also roll? How to deal with it? The scrolling inside must add bindSelf and prevent bubbling:

Let’s look at the detailed code of the internal scrolling:

var scroller = document.querySelector("#scroller");
Transform(scroller,true);
 
new AlloyTouch({
  touch:"#demo0",
  target: scroller,
  property: "translateY",
  min:250-2000,
  max: 0 ,
  touchStart:function(evt){
    evt.stopPropagation();
  },
  touchMove:function(evt){
    evt.stopPropagation();
  },
  bindSelf:true
})
Copy after login

In this case, the nesting inside the nested HTML AlloyTouch will not bubble up, that is, scrolling inside will not trigger outside scrolling.

Continue to analyze the FullPage source code:

touchEnd is the callback function after the user's finger leaves the screen. There is boundary processing logic in it:

If min and max are exceeded, min and max will be corrected accordingly.

step correction, if the absolute value is less than 30px, it will be reset

step correction, if the absolute value is greater than 30px and greater than 0, it will go to the previous page

step correction, if the absolute value is greater than 30px and If it is less than 0, it will go to the next page.

Return false means that the movement correction logic after AlloyTouch releases your hand will not be run. This is very important.

animationEnd is the callback after the movement ends. The function will execute the animationEnd passed by the user from AlloyTouch.FullPage, and set moving to false.

Start the journey of AlloyTouch.FullPage

Github: https://github.com/AlloyTeam/AlloyTouch

The above is the entire content of this article, I hope it will be helpful to everyone The learning is helpful, and I hope everyone will support the PHP Chinese website.

For more AlloyTouch full-screen scrolling plug-in, you can create a smooth H5 page in 30 seconds. For related articles, please pay attention to the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
H5 Code: Accessibility and Semantic HTML H5 Code: Accessibility and Semantic HTML Apr 09, 2025 am 12:05 AM

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.

What Does H5 Refer To? Exploring the Context What Does H5 Refer To? Exploring the Context Apr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

H5: The Evolution of Web Standards and Technologies H5: The Evolution of Web Standards and Technologies Apr 15, 2025 am 12:12 AM

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.

H5 Code: Best Practices for Web Developers H5 Code: Best Practices for Web Developers Apr 16, 2025 am 12:14 AM

Best practices for H5 code include: 1. Use correct DOCTYPE declarations and character encoding; 2. Use semantic tags; 3. Reduce HTTP requests; 4. Use asynchronous loading; 5. Optimize images. These practices can improve the efficiency, maintainability and user experience of web pages.

H5: Tools, Frameworks, and Best Practices H5: Tools, Frameworks, and Best Practices Apr 11, 2025 am 12:11 AM

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.

Is H5 a Shorthand for HTML5? Exploring the Details Is H5 a Shorthand for HTML5? Exploring the Details Apr 14, 2025 am 12:05 AM

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5: Commonly Used Terms in Web Development H5 and HTML5: Commonly Used Terms in Web Development Apr 13, 2025 am 12:01 AM

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

The Legacy of HTML5: Understanding H5 in the Present The Legacy of HTML5: Understanding H5 in the Present Apr 10, 2025 am 09:28 AM

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

See all articles