SlideShare a Scribd company logo
1 of 3
Replicating the iPhone Swipe Gesture – common code for mobiles
and computer browsers.
Actual Blog post link: http://jbkflex.wordpress.com/2012/07/21/replicating-the-iphone-swipe-gesture-
common-code-for-mobiles-and-desktop-browsers/

This is another update for the iPhone Swipe Gesture that I have created. This is the third update to the series – Part
1 and Part 2. In case you have missed out of the earlier tutorials and detailed explanation then you can have a look
at them first, before proceeding with this tutorial. What I have been able to achieve is that, I have replicated the native
iPhone swipe gesture for the iPhone web-kit browser. So, throughout the series I have been able to create a
HTML/JavaScript/CSS3 version of the swipe gesture. If in case, again you are not sure of the swipe gesture and
swiping, I would recommend to go through my previous tutorials – Part1 and Part2.
Now, the update and the agenda of this tutorial is that – I have developed a common universal code for mobile
browsers and computer browsers. Note that when I am saying browsers I mean web-kit browsers – Chrome & Safari
in computers, and then the default web browsers in iOS and Android mobiles. The major changes are in the
javascript code, where I have automated the user event handling process. What this means is that for mobile devices
touch based events are registered and listened to and then for computer browsers mouse based events are
registered and handled by the script automatically. This way there is no need to hard code touch events for mobiles
and mouse events for computers. The same code works everywhere.
But, still to support different device screen sizes you will need to make changes to the CSS or the asset (images)
sizes. The demo that I have worked on, I have considered the iPhone resolution – 320 x 416.
Check out the demo (same link works in mobiles and
computers): http://rialab.jbk404.site50.net/swipegesture/common/
Common implementation for mobiles and computers

So this new updated demo is the latest one including all the previous updates. Following are the features,
         Fix – Flickering issue in iOS and Android – Read the post.
         Images linked to separate URL – Read the post.
         Common code. Write once run everywhere. Same demo works in mobiles and computers.
         Basic swiping feature – which I have developed in my previous tutorials – Start here.
I will not go into the details, you can check my previous posts for that. I will just update you with the changes I made
in the script.
Detect device type and automatically assign events
I have written a completely separate post for this. You can have a look at it. Just to give you a hint, this is what I did,

//detect touch and then automatically assign events

isTouchSupported: 'ontouchstart' in window.document,




/*mapping touch events to mouse events. Automatic registration of event

based on the device. If touch enabled then touch event is registered.
and if desktop browser then mouse event is registered.*/

swipey.startEvent = swipey.isTouchSupported ? 'touchstart' : 'mousedown',

swipey.moveEvent = swipey.isTouchSupported ? 'touchmove' : 'mousemove',

swipey.endEvent = swipey.isTouchSupported ? 'touchend' : 'mouseup',


This detects if the device browser window supports touch event. If yes, then javascript touch events are assigned to
our startEvent, moveEvent and endEvent properties of the swipey object. And if touch is not supported, it is a
computer browser and so mouse events are assigned to our swipey object’s custom properties. This creates an
automated event detection mechanism.
Another automation has been done in the way the page co-ordinates are read when the user is interacting with the
app,

var eventObj = swipey.isTouchSupported ? event.touches[0] : event;


You can find this inside the startHandler() and the moveHandler() – event listener functions. Then when we need to
read the page co-ordinates we do this,

swipey.distanceX = eventObj.pageX - swipey.startX;


This is it, these are some of the major changes in the code. You can download the source and try it out. Download
link is given below. Again, I would recommend you to go through my previous post to fully get a hang of it.
Download
Download the source here.

More Related Content

More from Joseph Khan

BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsJoseph Khan
 
Creating dynamic SVG elements in JavaScript
Creating dynamic SVG elements in JavaScriptCreating dynamic SVG elements in JavaScript
Creating dynamic SVG elements in JavaScriptJoseph Khan
 
Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 2
Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 2Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 2
Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 2Joseph Khan
 
Customizing the list control - Sencha Touch mobile web application
Customizing the list control - Sencha Touch mobile web applicationCustomizing the list control - Sencha Touch mobile web application
Customizing the list control - Sencha Touch mobile web applicationJoseph Khan
 
Introduction to Adobe Flex - Zaloni
Introduction to Adobe Flex - ZaloniIntroduction to Adobe Flex - Zaloni
Introduction to Adobe Flex - ZaloniJoseph Khan
 
Building Cool apps with flex
Building Cool apps with flexBuilding Cool apps with flex
Building Cool apps with flexJoseph Khan
 

More from Joseph Khan (6)

BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
 
Creating dynamic SVG elements in JavaScript
Creating dynamic SVG elements in JavaScriptCreating dynamic SVG elements in JavaScript
Creating dynamic SVG elements in JavaScript
 
Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 2
Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 2Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 2
Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 2
 
Customizing the list control - Sencha Touch mobile web application
Customizing the list control - Sencha Touch mobile web applicationCustomizing the list control - Sencha Touch mobile web application
Customizing the list control - Sencha Touch mobile web application
 
Introduction to Adobe Flex - Zaloni
Introduction to Adobe Flex - ZaloniIntroduction to Adobe Flex - Zaloni
Introduction to Adobe Flex - Zaloni
 
Building Cool apps with flex
Building Cool apps with flexBuilding Cool apps with flex
Building Cool apps with flex
 

Recently uploaded

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
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 WorkerThousandEyes
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Recently uploaded (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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...
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Replicating the iPhone Swipe Gesture – common code for mobiles and computer browsers.

  • 1. Replicating the iPhone Swipe Gesture – common code for mobiles and computer browsers. Actual Blog post link: http://jbkflex.wordpress.com/2012/07/21/replicating-the-iphone-swipe-gesture- common-code-for-mobiles-and-desktop-browsers/ This is another update for the iPhone Swipe Gesture that I have created. This is the third update to the series – Part 1 and Part 2. In case you have missed out of the earlier tutorials and detailed explanation then you can have a look at them first, before proceeding with this tutorial. What I have been able to achieve is that, I have replicated the native iPhone swipe gesture for the iPhone web-kit browser. So, throughout the series I have been able to create a HTML/JavaScript/CSS3 version of the swipe gesture. If in case, again you are not sure of the swipe gesture and swiping, I would recommend to go through my previous tutorials – Part1 and Part2. Now, the update and the agenda of this tutorial is that – I have developed a common universal code for mobile browsers and computer browsers. Note that when I am saying browsers I mean web-kit browsers – Chrome & Safari in computers, and then the default web browsers in iOS and Android mobiles. The major changes are in the javascript code, where I have automated the user event handling process. What this means is that for mobile devices touch based events are registered and listened to and then for computer browsers mouse based events are registered and handled by the script automatically. This way there is no need to hard code touch events for mobiles and mouse events for computers. The same code works everywhere. But, still to support different device screen sizes you will need to make changes to the CSS or the asset (images) sizes. The demo that I have worked on, I have considered the iPhone resolution – 320 x 416. Check out the demo (same link works in mobiles and computers): http://rialab.jbk404.site50.net/swipegesture/common/
  • 2. Common implementation for mobiles and computers So this new updated demo is the latest one including all the previous updates. Following are the features,  Fix – Flickering issue in iOS and Android – Read the post.  Images linked to separate URL – Read the post.  Common code. Write once run everywhere. Same demo works in mobiles and computers.  Basic swiping feature – which I have developed in my previous tutorials – Start here. I will not go into the details, you can check my previous posts for that. I will just update you with the changes I made in the script. Detect device type and automatically assign events I have written a completely separate post for this. You can have a look at it. Just to give you a hint, this is what I did, //detect touch and then automatically assign events isTouchSupported: 'ontouchstart' in window.document, /*mapping touch events to mouse events. Automatic registration of event based on the device. If touch enabled then touch event is registered.
  • 3. and if desktop browser then mouse event is registered.*/ swipey.startEvent = swipey.isTouchSupported ? 'touchstart' : 'mousedown', swipey.moveEvent = swipey.isTouchSupported ? 'touchmove' : 'mousemove', swipey.endEvent = swipey.isTouchSupported ? 'touchend' : 'mouseup', This detects if the device browser window supports touch event. If yes, then javascript touch events are assigned to our startEvent, moveEvent and endEvent properties of the swipey object. And if touch is not supported, it is a computer browser and so mouse events are assigned to our swipey object’s custom properties. This creates an automated event detection mechanism. Another automation has been done in the way the page co-ordinates are read when the user is interacting with the app, var eventObj = swipey.isTouchSupported ? event.touches[0] : event; You can find this inside the startHandler() and the moveHandler() – event listener functions. Then when we need to read the page co-ordinates we do this, swipey.distanceX = eventObj.pageX - swipey.startX; This is it, these are some of the major changes in the code. You can download the source and try it out. Download link is given below. Again, I would recommend you to go through my previous post to fully get a hang of it. Download Download the source here.