SlideShare uma empresa Scribd logo
1 de 8
Baixar para ler offline
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

Mais conteúdo relacionado

Destaque

Html5三种本地存储方式的比较
Html5三种本地存储方式的比较Html5三种本地存储方式的比较
Html5三种本地存储方式的比较sunnylqm
 
John Hayes Slide Share
John Hayes Slide ShareJohn Hayes Slide Share
John Hayes Slide ShareJohn Hayes
 
Who are SBS.doc
Who are SBS.docWho are SBS.doc
Who are SBS.docSally15
 
Environmental dimension in education process
Environmental dimension in education processEnvironmental dimension in education process
Environmental dimension in education processCarmina Gurrea
 
NED 203 Criterion Referenced Test & Rubrics
NED 203 Criterion Referenced Test & RubricsNED 203 Criterion Referenced Test & Rubrics
NED 203 Criterion Referenced Test & RubricsCarmina Gurrea
 
Gastrointestinal medications
Gastrointestinal medicationsGastrointestinal medications
Gastrointestinal medicationsCarmina Gurrea
 
Blood transfusion skills
Blood transfusion skillsBlood transfusion skills
Blood transfusion skillsCarmina Gurrea
 

Destaque (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
 

Último

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 productivityPrincipled Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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 Servicegiselly40
 
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 interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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 2024Rafal Los
 
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 Nanonetsnaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
[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.pdfhans926745
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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...Miguel Araújo
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Último (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
[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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

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