search
HomeWeb Front-endH5 TutorialAlloyTouch full-screen scrolling plug-in creates a smooth H5 page in 30 seconds

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="/static/imghwm/default1.png"  data-src="asset/alloytouch.png"  class="lazy"   alt="AlloyTouch full-screen scrolling plug-in creates a smooth H5 page in 30 seconds" ></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="/static/imghwm/default1.png"  data-src="asset/power.png"  class="lazy"   alt="AlloyTouch full-screen scrolling plug-in creates a smooth H5 page in 30 seconds" ></div>
      </div>
    </div>
    ...
    ...
    ...
 </div>

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));
    }
  });

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;
  }
});

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
})

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
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
What is the H5 tag in HTML?What is the H5 tag in HTML?May 09, 2025 am 12:11 AM

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

H5 Code: A Beginner's Guide to Web StructureH5 Code: A Beginner's Guide to Web StructureMay 08, 2025 am 12:15 AM

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

H5 Code Structure: Organizing Content for ReadabilityH5 Code Structure: Organizing Content for ReadabilityMay 07, 2025 am 12:06 AM

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

H5 vs. Older HTML Versions: A ComparisonH5 vs. Older HTML Versions: A ComparisonMay 06, 2025 am 12:09 AM

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

H5 vs. HTML5: Clarifying the Terminology and RelationshipH5 vs. HTML5: Clarifying the Terminology and RelationshipMay 05, 2025 am 12:02 AM

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

HTML5 Features: The Core of H5HTML5 Features: The Core of H5May 04, 2025 am 12:05 AM

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.

H5: Exploring the Latest Version of HTMLH5: Exploring the Latest Version of HTMLMay 03, 2025 am 12:14 AM

HTML5isamajorrevisionoftheHTMLstandardthatrevolutionizeswebdevelopmentbyintroducingnewsemanticelementsandcapabilities.1)ItenhancescodereadabilityandSEOwithelementslike,,,and.2)HTML5enablesricher,interactiveexperienceswithoutplugins,allowingdirectembe

Beyond Basics: Advanced Techniques in H5 CodeBeyond Basics: Advanced Techniques in H5 CodeMay 02, 2025 am 12:03 AM

Advanced tips for H5 include: 1. Use complex graphics to draw, 2. Use WebWorkers to improve performance, 3. Enhance user experience through WebStorage, 4. Implement responsive design, 5. Use WebRTC to achieve real-time communication, 6. Perform performance optimization and best practices. These tips help developers build more dynamic, interactive and efficient web applications.

See all articles

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version