Home Web Front-end H5 Tutorial Share an example code that uses H5 to implement drop-down top zoom

Share an example code that uses H5 to implement drop-down top zoom

May 10, 2017 pm 01:55 PM

Share an example code that uses H5 to implement drop-down top zoom style="max-width:90%"/>

Imitation app drop-down zoom.gif


This article only provides design ideas, that is, jsCode. For complete code, please download the demo
Design ideas:

1. Monitor the touchstart event of the entire drop-down area, and record the pageY and clientY values

content.addEventListener('touchstart',function (event) {
    var touch = event.touches[0];
    startY = touch.pageY;
    clientY = touch.clientY;    
});
Copy after login

2. Listen to the touchmove event of the entire area, and determine whether to move up or down, and whether clientY and pageY are equal when the scroll starts, and finally implement animation

content.addEventListener('touchmove',function  (event) {

    var touchs = event.touches[0];
      //向上滚动,直接返回
    if (touchs.pageY - startY <= 0 ) {
        return ;
    }
    //不相等,说明屏幕已经向上翻动,image不需要放大效果
    if(startY != clientY){
        return ;
    }

    var header = document.getElementById(&#39;headers&#39;);
    //图片底部的容器高度+拖动的高度
    header.style.height = 300  + touchs.pageY - startY +&#39;px&#39;;
    //图片放大比例 
    var scale = (touchs.pageY - startY ) / 300 + 1.0;
    //图片放大
    imag.style.transform = "scale("+ scale +","+ scale +")";

});
Copy after login

3. When the sliding stops, the headView changes to the original one, and the picture returns to its original state

content.addEventListener(&#39;touchend&#39;,function  (event) {
    event.preventDefault();
    var touch = event.changedTouches[0];    
    var header = document.getElementById(&#39;headers&#39;);

    header.style.height = 300 +&#39;px&#39;;        
    imag.style.transform = "none";
    console.log("滑动结束");

});
Copy after login

【Related recommendations 】

1. Free h5 online video tutorial

2. HTML5 full version manual

3. php .cn original html5 video tutorial

The above is the detailed content of Share an example code that uses H5 to implement drop-down top zoom. For more information, please follow other related articles on 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

SVM examples in Python SVM examples in Python Jun 11, 2023 pm 08:42 PM

Support Vector Machine (SVM) in Python is a powerful supervised learning algorithm that can be used to solve classification and regression problems. SVM performs well when dealing with high-dimensional data and non-linear problems, and is widely used in data mining, image classification, text classification, bioinformatics and other fields. In this article, we will introduce an example of using SVM for classification in Python. We will use the SVM model from the scikit-learn library

How to implement the zoom function of a specific area of ​​an image through Vue? How to implement the zoom function of a specific area of ​​an image through Vue? Aug 26, 2023 pm 04:43 PM

How to implement the zoom function of a specific area of ​​an image through Vue? Introduction: In web design and development, we often encounter situations where larger images need to be displayed. In order to provide a better user experience, users are often expected to zoom in on certain areas to view details. This article will introduce how to implement the zoom function of specific areas of the picture through Vue, so that users can easily view the details of the picture. Technical preparation: Before implementing this function, you need to prepare the following technical tools: Vue.js: a JavaScript for building interactive user interfaces

HTML, CSS and jQuery: Techniques for achieving special effects of zooming in and out of images HTML, CSS and jQuery: Techniques for achieving special effects of zooming in and out of images Oct 24, 2023 am 10:22 AM

HTML, CSS and jQuery: Techniques for implementing image zoom-in and zoom-out effects, specific code examples are required. With the development of the Internet, the design of web pages pays more and more attention to user experience. Among them, pictures, as one of the important elements of web design, can often bring users an intuitive and rich visual experience. The special effect of zooming in and out of images can enhance users' perception and interaction with web content, so it is widely used in web design. This article will introduce how to use HTML, CSS and jQuery to achieve special effects of zooming in and out of images, and provide

What does h5 mean? What does h5 mean? Aug 02, 2023 pm 01:52 PM

H5 refers to HTML5, the latest version of HTML. H5 is a powerful markup language that provides developers with more choices and creative space. Its emergence promotes the development of Web technology, making the interaction and effect of web pages more Excellent, as H5 technology gradually matures and becomes popular, I believe it will play an increasingly important role in the Internet world.

Unlock macOS clipboard history, efficient copy and paste techniques Unlock macOS clipboard history, efficient copy and paste techniques Feb 19, 2024 pm 01:18 PM

On Mac, it's common to need to copy and paste content between different documents. The macOS clipboard only retains the last copied item, which limits our work efficiency. Fortunately, there are some third-party applications that can help us view and manage our clipboard history easily. How to View Clipboard Contents in Finder There is a built-in clipboard viewer in Finder, allowing you to view the contents of the current clipboard at any time to avoid pasting errors. The operation is very simple: open the Finder, click the Edit menu, and then select Show Clipboard. Although the function of viewing the contents of the clipboard in the Finder is small, there are a few points to note: the clipboard viewer in the Finder can only display the contents and cannot edit them. If you copied

How to distinguish between H5, WEB front-end, big front-end, and WEB full stack? How to distinguish between H5, WEB front-end, big front-end, and WEB full stack? Aug 03, 2022 pm 04:00 PM

This article will help you quickly distinguish between H5, WEB front-end, large front-end, and WEB full stack. I hope it will be helpful to friends in need!

VUE3 Getting Started Example: Making a Simple Video Player VUE3 Getting Started Example: Making a Simple Video Player Jun 15, 2023 pm 09:42 PM

As the new generation of front-end frameworks continues to emerge, VUE3 is loved as a fast, flexible, and easy-to-use front-end framework. Next, let's learn the basics of VUE3 and make a simple video player. 1. Install VUE3 First, we need to install VUE3 locally. Open the command line tool and execute the following command: npminstallvue@next Then, create a new HTML file and introduce VUE3: &lt;!doctypehtml&gt;

Learn best practice examples of pointer conversion in Golang Learn best practice examples of pointer conversion in Golang Feb 24, 2024 pm 03:51 PM

Golang is a powerful and efficient programming language that can be used to develop various applications and services. In Golang, pointers are a very important concept, which can help us operate data more flexibly and efficiently. Pointer conversion refers to the process of pointer operations between different types. This article will use specific examples to learn the best practices of pointer conversion in Golang. 1. Basic concepts In Golang, each variable has an address, and the address is the location of the variable in memory.

See all articles