


Implementation of screen orientation change and scrolling in JQuery mobile page development_jquery
Orientation change event (orientationchange)
This event is triggered when the orientation of the device changes (the device is held horizontally or vertically). When binding this event, your callback function can add a second parameter, which is used to describe the horizontal or vertical attributes of the device, "portrait" or; landscape. These values will also be added to html elements as class values, so that You can change their styles through selectors in css. Note that we now bind the resize event when the browser does not support the orientationChange event.
$(window).bind( 'orientationchange', function(e){ var height=document.body.clientHeight - 195; $("#content").css("min-height",height); $("#thumb").css("margin",height/4.2 + "px auto"); });
$(function(){ $('a').click(function(){ $(window).trigger('orientationchange' ); }); });
Binding to the orientationchange event requires you to position the body element and then use the bind method to bind the event. It's also important to bind the orientationchange event to the body, but wait until the element is ready in the document before binding the event. Otherwise, you will get inconsistent results because the body element may not be available at binding time. You can also enhance this code further to fire the orientationchange event when the document is ready.
The orientationchange event is triggered when the document is ready
<!DOCTYPE HTML> <html> <head> <title>Understanding the jQuery Mobile API</title> <link rel="stylesheet" href="jquery.mobile.css" /> <script src="jquery.js"></script> <script type="text/java script"> $(document).ready(function(){ $(".tap-hold-test").bind("taphold", function(event) { $(this).html("Tapped and held"); }); }); </script> <script src="jquery.mobile.js"></script> </head> <body> <div data-role="page" id="my-page"> <div data-role="header"> <h1>Header</h1> </div> <div data-role="content"> <ul data-role="listview" id="my-list"> <li class="tap-hold-test">Tap and hold test</li> </ul> </div> </div> </body> </html> $(document).ready(function(){ $('body').bind('orientationchange', function(event) { alert('orientationchange: '+ event.orientation); }); });
Scroll events (scrollstart, scrollstop)
scrollstart: Triggered when screen scrolling starts. Apple's devices will freeze DOM operations during scrolling, and execute these DOM operations in a queue when the scrolling ends. We are currently studying methods to allow Apple's devices to perform DOM operations before scrolling begins.
$(document).ready(function(){ $('body').bind('scrollstart', function(event) { // Add scroll start code here }); });
$(document).ready(function(){ $('body').bind('scrollstop', function(event) { // Add scroll stop code here }); });
<!DOCTYPE html> <html> <head> <title>Ajax测试</title> <meta charset="gbk"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="jquery-mobile/jquery.mobile-1.2.0.min.css"/> <link rel="stylesheet" href="jquery-mobile/jquery.mobile.structure-1.2.0.min.css"/> <script src="jquery-mobile/jquery-1.8.2.min.js"></script> <script src="jquery-mobile/jquery.mobile-1.2.0.min.js"></script> </head> <body> <div data-role="page" data-theme="b"> <div data-role="header"></div> <div data-role="content"> <script> //scrollstart事件 function scrollstartFunc(evt) { try { var target = $(evt.target); while (target.attr("id") == undefined) { target = target.parent(); } //获取触点目标id属性值 var targetId = target.attr("id"); alert("targetId: " + targetId); } catch (e) { alert('myscrollfunc:' + e.message); } } function myinit() { //绑定上下滑动事件 $("#myul").bind('scrollstart', function () { scrollstartFunc(event); }); } window.onload = myinit; </script> <!-- listview测试 --> <ul id="myul" data-role="listview" data-inset="true"> <li data-role="list-divider">信息列表</li> <li id="li1" data-role="fieldcontain">信息1</li> <li id="li2" data-role="fieldcontain">信息2</li> <li id="li3" data-role="fieldcontain">信息3</li> <li id="li4" data-role="fieldcontain">信息4</li> <li id="li5" data-role="fieldcontain">信息5</li> <li id="li6" data-role="fieldcontain">信息6</li> <li id="li7" data-role="fieldcontain">信息7</li> <li id="li8" data-role="fieldcontain">信息8</li> <li id="li9" data-role="fieldcontain">信息9</li> <li id="li10" data-role="fieldcontain">信息10</li> </ul> </div> </body> </html>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



According to news on July 23, blogger Digital Chat Station broke the news that the battery capacity of Xiaomi 15 Pro has been increased to 6000mAh and supports 90W wired flash charging. This will be the Pro model with the largest battery in Xiaomi’s digital series. Digital Chat Station previously revealed that the battery of Xiaomi 15Pro has ultra-high energy density and the silicon content is much higher than that of competing products. After silicon-based batteries are tested on a large scale in 2023, second-generation silicon anode batteries have been identified as the future development direction of the industry. This year will usher in the peak of direct competition. 1. The theoretical gram capacity of silicon can reach 4200mAh/g, which is more than 10 times the gram capacity of graphite (the theoretical gram capacity of graphite is 372mAh/g). For the negative electrode, the capacity when the lithium ion insertion amount reaches the maximum is the theoretical gram capacity, which means that under the same weight

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

"Operation Delta" will launch a large-scale PC test called "Codename: ZERO" today (March 7). Last weekend, this game held an offline flash mob experience event in Shanghai, and 17173 was also fortunate to be invited to participate. This test is only more than four months away from the last time, which makes us curious, what new highlights and surprises will "Operation Delta" bring in such a short period of time? More than four months ago, I experienced "Operation Delta" in an offline tasting session and the first beta version. At that time, the game only opened the "Dangerous Action" mode. However, Operation Delta was already impressive for its time. In the context of major manufacturers flocking to the mobile game market, such an FPS that is comparable to international standards

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

Recently, Honor Mobile held a new product launch conference and officially launched the Honor Magic6RSR Porsche Design. On March 22, CNMO learned that the Honor Magic 6 RSR Porsche Design was officially launched for sale, with only a 24GB+1TB version available for 9,999 yuan. Honor Magic6 RSR adopts a Porsche design appearance, inspired by the classic elements of Porsche super sports cars. The back line design is inspired by the Porsche flying line design, and the camera module adopts the iconic hexagonal design, giving the product a distinct three-dimensional and dynamic feel. In addition, the product is available in two colors, agate gray and iceberry pink, which are color-tuned by Porsche original masters, further highlighting its unique design beauty. In terms of screen technology, Honor Magic6RSR maintains
