SlideShare une entreprise Scribd logo
1  sur  8
Télécharger pour lire hors ligne
WEBKIT
    TOUCH
     2011-07-03
mouse


Reference:
http://www.quirksmode.org/blog/archives/2008/08/iphone_events.html
Moving your fingers
	

 	

 is not the same as moving the mouse

            mouse
                                touch
• touchstart – triggered when a touch is initiated. Mouse equivalent –
  mouseDown
• touchmove – triggered when a touch moves. Mouse equivalent – mouseMove
• touchend – triggered when a touch ends. Mouse equivalent – mouseUp.
• touchcancel – triggered when a touch leaves the the region that is listening,
  e.g., when a finger that is in contact with the screen moves off-screen (iOS
  only)
Register handlers for multi-touch events in HTML as follows:
<div
  ontouchstart="touchStart(event);"
  ontouchmove="touchMove(event);"
  ontouchend="touchEnd(event);"
  ontouchcancel="touchCancel(event);"
></div>


Alternatively, register handlers in JavaScript as follows:
element.addEventListener("touchstart",
touchStart, false);
element.addEventListener("touchmove", touchMove,
false);
element.addEventListener("touchend", touchEnd,
false);
element.addEventListener("touchcancel",
touchCancel, false);
touches/targetTouches/
              changedTouches
get all touches on a page using the touches property

get all touches for the target element using the targetTouches property

get all changed touches for this event using the changedTouches property

get the location in page coordinates for a single-finger event:
var x = event.touches[0].pageX;
var y = event.touches[0].pageY;
Slide demo             <section class="slide">
                       !    <div class="gallery">
  using Touch events   !    !    <ul>
                       !    !    !    <li>
                                         <a href=#><img/></a><a href=#><img/></a>
                                     </li>
                       !    !    !    <li>
                                         <a href=#><img/></a><a href=#><img/></a>
                                     </li>
                       !    !    !    <li>
                                         <a href=#><img/></a><a href=#><img/></a>
                                     </li>
                       !    !    !    <li>
                                         <a href=#><img/></a><a href=#><img/></a>
                                     </li>
                       !    !    </ul>
                       !    </div>
                       !    <div class="scrlCtrl">
                       !    !    <ul>
                       !    !    !    <li class="active"></li><li></li><li></li><li></li>
                       !    !    </ul>
                       !    </div>
                       </section>
var imglist = X('.gallery li'),ctrllist = X('.scrlCtrl li'),startX,cIndex=0,cOffset=0;
X('.slide').touchstart(function(e){
&     startX = e.targetTouches[0].pageX;               //           X
&     imglist.css({webkitTransitionDuration:'0s'});
}).touchmove(function(e){
&     //e.preventDefault(); //                                       scroll
&     var curX = e.targetTouches[0].pageX - startX; //                move
&     imglist.css({webkitTransform:'translate3d(' + (curX+cOffset) + 'px,0,0)'}); //imglist      translate
}).touchend(function(e){
&     var curX = e.changedTouches[0].pageX - startX;
&     if(curX<-50&&cIndex<imglist.length-1){// to left
&     &     ctrllist[cIndex].className = '';
&     &     ctrllist[++cIndex].className = 'active';& &
&     &     cOffset = -640*cIndex;             //iPhone4         640px
&     &     imglist.css({webkitTransform:'translate3d('+cOffset+'px,0,0)',webkitTransitionDuration:'.5s'});
&     }
&     else if(curX>50&&cIndex>0){//to right
&     &     ctrllist[cIndex].className = '';
&     &     ctrllist[--cIndex].className = 'active';&
&     &     cOffset = -640*cIndex;
&     &     imglist.css({webkitTransform:'translate3d('+cOffset+'px,0,0)',webkitTransitionDuration:'.5s'});
&     }
&     else{ //                 50px
&     &     imglist.css({webkitTransform:'translate3d('+cOffset+'px,0,0)',webkitTransitionDuration:'.5s'});
&     }
});
Bonus Tips
          translateX/Y               translate3d(x,y,z)


              iOS/android            position:fixed   android    border-radius


iPhone                      option                android


    css sprites                          1px


iOS/android                   js

android           meta   viewport    target-densityDpi=device-dpi
    dpi

Contenu connexe

En vedette (9)

Html5三种本地存储方式的比较
Html5三种本地存储方式的比较Html5三种本地存储方式的比较
Html5三种本地存储方式的比较
 
Gouri engineering-pvt-ltd
Gouri engineering-pvt-ltdGouri engineering-pvt-ltd
Gouri engineering-pvt-ltd
 
John Hayes Slide Share
John Hayes Slide ShareJohn Hayes Slide Share
John Hayes Slide Share
 
Who are SBS.doc
Who are SBS.docWho are SBS.doc
Who are SBS.doc
 
Environmental dimension in education process
Environmental dimension in education processEnvironmental dimension in education process
Environmental dimension in education process
 
A report in ned 201
A report in ned 201A report in ned 201
A report in ned 201
 
NED 203 Criterion Referenced Test & Rubrics
NED 203 Criterion Referenced Test & RubricsNED 203 Criterion Referenced Test & Rubrics
NED 203 Criterion Referenced Test & Rubrics
 
Gastrointestinal medications
Gastrointestinal medicationsGastrointestinal medications
Gastrointestinal medications
 
Blood transfusion skills
Blood transfusion skillsBlood transfusion skills
Blood transfusion skills
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Webkit核心移动浏览器上的touch事件处理

  • 1. WEBKIT TOUCH 2011-07-03
  • 3. Moving your fingers is not the same as moving the mouse mouse touch • touchstart – triggered when a touch is initiated. Mouse equivalent – mouseDown • touchmove – triggered when a touch moves. Mouse equivalent – mouseMove • touchend – triggered when a touch ends. Mouse equivalent – mouseUp. • touchcancel – triggered when a touch leaves the the region that is listening, e.g., when a finger that is in contact with the screen moves off-screen (iOS only)
  • 4. Register handlers for multi-touch events in HTML as follows: <div ontouchstart="touchStart(event);" ontouchmove="touchMove(event);" ontouchend="touchEnd(event);" ontouchcancel="touchCancel(event);" ></div> Alternatively, register handlers in JavaScript as follows: element.addEventListener("touchstart", touchStart, false); element.addEventListener("touchmove", touchMove, false); element.addEventListener("touchend", touchEnd, false); element.addEventListener("touchcancel", touchCancel, false);
  • 5. touches/targetTouches/ changedTouches get all touches on a page using the touches property get all touches for the target element using the targetTouches property get all changed touches for this event using the changedTouches property get the location in page coordinates for a single-finger event: var x = event.touches[0].pageX; var y = event.touches[0].pageY;
  • 6. Slide demo <section class="slide"> ! <div class="gallery"> using Touch events ! ! <ul> ! ! ! <li> <a href=#><img/></a><a href=#><img/></a> </li> ! ! ! <li> <a href=#><img/></a><a href=#><img/></a> </li> ! ! ! <li> <a href=#><img/></a><a href=#><img/></a> </li> ! ! ! <li> <a href=#><img/></a><a href=#><img/></a> </li> ! ! </ul> ! </div> ! <div class="scrlCtrl"> ! ! <ul> ! ! ! <li class="active"></li><li></li><li></li><li></li> ! ! </ul> ! </div> </section>
  • 7. var imglist = X('.gallery li'),ctrllist = X('.scrlCtrl li'),startX,cIndex=0,cOffset=0; X('.slide').touchstart(function(e){ & startX = e.targetTouches[0].pageX; // X & imglist.css({webkitTransitionDuration:'0s'}); }).touchmove(function(e){ & //e.preventDefault(); // scroll & var curX = e.targetTouches[0].pageX - startX; // move & imglist.css({webkitTransform:'translate3d(' + (curX+cOffset) + 'px,0,0)'}); //imglist translate }).touchend(function(e){ & var curX = e.changedTouches[0].pageX - startX; & if(curX<-50&&cIndex<imglist.length-1){// to left & & ctrllist[cIndex].className = ''; & & ctrllist[++cIndex].className = 'active';& & & & cOffset = -640*cIndex; //iPhone4 640px & & imglist.css({webkitTransform:'translate3d('+cOffset+'px,0,0)',webkitTransitionDuration:'.5s'}); & } & else if(curX>50&&cIndex>0){//to right & & ctrllist[cIndex].className = ''; & & ctrllist[--cIndex].className = 'active';& & & cOffset = -640*cIndex; & & imglist.css({webkitTransform:'translate3d('+cOffset+'px,0,0)',webkitTransitionDuration:'.5s'}); & } & else{ // 50px & & imglist.css({webkitTransform:'translate3d('+cOffset+'px,0,0)',webkitTransitionDuration:'.5s'}); & } });
  • 8. Bonus Tips translateX/Y translate3d(x,y,z) iOS/android position:fixed android border-radius iPhone option android css sprites 1px iOS/android js android meta viewport target-densityDpi=device-dpi dpi