SlideShare una empresa de Scribd logo
1 de 4
Replicating the iPhone Swipe Gesture
– Vertical swiping
For the full post, visit the actual blog post link:
http://jbkflex.wordpress.com/2013/02/14/replicating-the-iphone-swipe-gesture-vertical-swiping/


For those who wanted a vertical swiping feature to the the swipe gesture gallery that I
created earlier, this post has a new demo and minimal explanation about a vertical swipe
gesture gallery. Now you can swipe the images up or down.
I will not go through the basics once again as I have explained them in details in my previous
posts. You can refer them once again in these two tutorials – post 1, post 2. Check out the demo
below. Open the link in a webkit browser in either your mobile device or your computer.
Demo link: http://rialab.jbk404.site50.net/swipegesture/vertical/
Below is a screenshot of the gallery in action. You can see that the images are being moved
vertically.




                           Screenshot of vertical swiping through images

Code Changes
There are not any major changes in the code. The logic is still the same. For vertical movement,
you just need to calculate the distance covered by your finger/mouse in y-direction and then
move the gallery by that distance in the y-axis. I have described the basic logic completely in my
previous post. So check it out to have a clear understanding of making a swipe gesture effect
with simple javascript and css3 transitions/transformation.
I will quickly talk on the changes that I made to make the swipe gesture go from horizontal x-
direction to vertical y-direction.
CSS
I have commented the line below. That’s not needed now.
#wrapper ul li


{


    /*float:left;*/


}


HTML
No changes.
JavaScript
I do have some changes. Let’s see what they are,
1) Firstly startX and distanceX have been renamed to startY and distanceY , since we are
only concerned with y-axis.
2) Next change is in the dimension of the slideContainer <ul> element,


swipey.slideContainer.style.width = swipey.preferredWidth + "px";


swipey.slideContainer.style.height = (swipey.slides.length *
swipey.preferredHeight) + "px";


The height value has now increased to a multiple of the number of slides.


3) Max distance now depends on the height,


swipey.maxDistance = swipey.slides.length * swipey.preferredHeight;


4) Then inside the startHandler() method, startY is initialized as follows,
swipey.startY = eventObj.pageY;


Remember we are concerned with y-direction for vertical movement.


5) Then inside moveHandler() method we calculate the net distance moved in y-direction as
follows,


swipey.distanceY = eventObj.pageY - swipey.startY;


And we translate the <ul> container in y-axis using CSS3 Tranformations,


swipey.slideContainer.style.webkitTransform = "translate3d(0," +
(swipey.distanceY + swipey.currentDistance) + "px,0)";


6) Next changes lies inside the endHandler() method,


if (swipey.distanceY > 0) {


    swipey.direction = "down"; //since we are moving down. Earlier we set this
as "right".


}


if (swipey.distanceY < 0) {


    swipey.direction = "up"; //since we are moving up. Earlier we set this as
"left"


}


//the following conditions have been discussed in details


if ((swipey.direction == "down" && swipey.currentDistance == 0) ||
(swipey.direction == "up" && swipey.currentDistance == -(swipey.maxDistance -
swipey.preferredHeight))) {
    swipey.comeBack();
}
7) Final changes are inside moveUp(), moveDown() and comeBack() methods. They are similar
changes. So let’s look at one of them,


swipey.currentDistance += -swipey.preferredHeight; //currentDistance has now
to be updated by the height, since we are moving in y-dir.


And then we translate the <ul> container in y-axis using CSS3 tranformations.


swipey.slideContainer.style.webkitTransform = "translate3d(0," +
swipey.currentDistance + "px,0)";


And that’s it. These are enough for the images to be swiped vertically.


Check out the demo once again. In case you need the code, just right click and view the source.
For any queries feel free to post a comment below.

Más contenido relacionado

Más de 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
 

Más de 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
 

Último

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
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
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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 MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Último (20)

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
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
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

Replicating the iPhone Swipe Gesture – Vertical swiping

  • 1. Replicating the iPhone Swipe Gesture – Vertical swiping For the full post, visit the actual blog post link: http://jbkflex.wordpress.com/2013/02/14/replicating-the-iphone-swipe-gesture-vertical-swiping/ For those who wanted a vertical swiping feature to the the swipe gesture gallery that I created earlier, this post has a new demo and minimal explanation about a vertical swipe gesture gallery. Now you can swipe the images up or down. I will not go through the basics once again as I have explained them in details in my previous posts. You can refer them once again in these two tutorials – post 1, post 2. Check out the demo below. Open the link in a webkit browser in either your mobile device or your computer. Demo link: http://rialab.jbk404.site50.net/swipegesture/vertical/ Below is a screenshot of the gallery in action. You can see that the images are being moved vertically. Screenshot of vertical swiping through images Code Changes There are not any major changes in the code. The logic is still the same. For vertical movement, you just need to calculate the distance covered by your finger/mouse in y-direction and then
  • 2. move the gallery by that distance in the y-axis. I have described the basic logic completely in my previous post. So check it out to have a clear understanding of making a swipe gesture effect with simple javascript and css3 transitions/transformation. I will quickly talk on the changes that I made to make the swipe gesture go from horizontal x- direction to vertical y-direction. CSS I have commented the line below. That’s not needed now. #wrapper ul li { /*float:left;*/ } HTML No changes. JavaScript I do have some changes. Let’s see what they are, 1) Firstly startX and distanceX have been renamed to startY and distanceY , since we are only concerned with y-axis. 2) Next change is in the dimension of the slideContainer <ul> element, swipey.slideContainer.style.width = swipey.preferredWidth + "px"; swipey.slideContainer.style.height = (swipey.slides.length * swipey.preferredHeight) + "px"; The height value has now increased to a multiple of the number of slides. 3) Max distance now depends on the height, swipey.maxDistance = swipey.slides.length * swipey.preferredHeight; 4) Then inside the startHandler() method, startY is initialized as follows,
  • 3. swipey.startY = eventObj.pageY; Remember we are concerned with y-direction for vertical movement. 5) Then inside moveHandler() method we calculate the net distance moved in y-direction as follows, swipey.distanceY = eventObj.pageY - swipey.startY; And we translate the <ul> container in y-axis using CSS3 Tranformations, swipey.slideContainer.style.webkitTransform = "translate3d(0," + (swipey.distanceY + swipey.currentDistance) + "px,0)"; 6) Next changes lies inside the endHandler() method, if (swipey.distanceY > 0) { swipey.direction = "down"; //since we are moving down. Earlier we set this as "right". } if (swipey.distanceY < 0) { swipey.direction = "up"; //since we are moving up. Earlier we set this as "left" } //the following conditions have been discussed in details if ((swipey.direction == "down" && swipey.currentDistance == 0) || (swipey.direction == "up" && swipey.currentDistance == -(swipey.maxDistance - swipey.preferredHeight))) { swipey.comeBack();
  • 4. } 7) Final changes are inside moveUp(), moveDown() and comeBack() methods. They are similar changes. So let’s look at one of them, swipey.currentDistance += -swipey.preferredHeight; //currentDistance has now to be updated by the height, since we are moving in y-dir. And then we translate the <ul> container in y-axis using CSS3 tranformations. swipey.slideContainer.style.webkitTransform = "translate3d(0," + swipey.currentDistance + "px,0)"; And that’s it. These are enough for the images to be swiped vertically. Check out the demo once again. In case you need the code, just right click and view the source. For any queries feel free to post a comment below.