SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5
– Part 1
http://jbkflex.wordpress.com/2012/01/09/replicating-the-swipe-gesture-iphone-gallery-for-mobile-
web-html5-part-1/

In this tutorial we will talk about building up a Swipe Gesture photo gallery for iPhone, iPod using web technologies –
HTML5, CSS3 and JavaScript. To begin with, you might have viewed pictures in your iPhone or iPod photo library
and may remember how you used to swipe your finger across the screen of your device to view the next or the
previous image in the gallery. The same thing we are going to replicate and make a mobile web app. Our app will run
full screen on the mobile safari browser so this gives it a native look n feel. The features of this mobile web app
replicate the iPhone photo library’s default behaviors,
1.   Gently swipe across the screen left or right to view the neighboring images.
2.   Flickering of images. Swipe across quickly to view neighboring images. I say it harsh swipe across the screen.
3.   Current Image comes back if you do not swipe it enough across the screen.
4.   When the beginning or end of the list is reached, no matter how much you swipe the image always comes back.
First, view a desktop version of the demo to get a feel, drag your mouse over the picture left or right to view other
images and try out the features that I have just talked about (View in web-kit browsers – Chrome or
Safari):http://jbk404.site50.net/html5/mobile/swipey/
The same thing we are going to replicate for the mobile device. Now, our app is targeted for mobile web kitbrowsers
so it will run even on Android browsers. That’s the good thing about a mobile web app, write once run everywhere.
Below we have two images of the app running in my iPod Touch,




                                       An image/slide showing up in portrait mode
Change of slides when swiping

What is a Swipe gesture?
When you use your finger to drag on the mobile device’s screen it is called a swipe gesture. It is equivalent of a
mouse drag over a desktop browser. Remember that our app is a single touch application and not a multi touch app.
Even the default iPhone photo gallery is a single touch app. That means you can use only one finger at a time to
operate. Check out this video to get an idea:


The basic concept to start with
I have a picture above that explains the entire process. We have images placed inside <li> elements which acts as
slides and all these <li> elements are placed inside an <ul> element. The <li> elements are laid out horizontally since
we are building a horizontal gallery. This can easily be done by using float:left CSS property.

<div id="wrapper">

      <ul id="panelContainer">

        <li>

         <img src="img/1.jpg" width="100%" height="100%"/>

        </li>

        <li>

         <img src="img/2.jpg" width="100%" height="100%" />

        </li>

        .....

      </ul>

</div>


Now, we basically have to move the <ul> element (our slides container) left or right using CSS3 transition and
transformations (Hardware accelerated CSS3 transitions, this makes the animation much smooth) based on the
user’s swiping gesture interaction on the device screen. Ofcourse we have the four features that we have talked
about earlier and need to keep that in mind. So our transition and movements should follow these features and we
will have to code it out accordingly. We will talk about it later. Finally we have all our slides and the container inside a
wrapper. The wrapper is a <div> element with overflow:hidden. The wrapper occupies the entire browser screen
and acts as a masking element. This ensures that only one slide/image is seen at a time.
Preparing the slides
As I have already talked about, each image is placed inside a <li> element and let’s consider it to be a slide. So, we
place multiple such slides inside an <ul> element which is our slide container (Refer the HTML block above).
Normally, in an unordered list the <li> elements are placed vertically. To place the slides horizontally, this is how to do
it,

#wrapper ul

{

      list-style:none;

      margin:0;
padding:0;

    -webkit-transition: -webkit-transform 0.3s linear;

}

#wrapper ul li

{

 float:left;

}


We have set a float:left to our slides. And to the unordered list – the <ul> element we have set list-
style:none,padding and margin to 0. One important thing to note is that for our slides to be placed horizontally we
have to set enough width to the slide container (<ul>) so that there is room for all the slides and there is no slide
wrapping i.e placing slides in a new line after full width is reached. I will talk about this in the java script part. First,
let’s check out the full HTML and CSS needed for our app,

body

{

    margin:0;

    padding:10px;

}




#wrapper

{

    overflow:hidden;

}




#wrapper ul

{

    list-style:none;
margin:0;

    padding:0;

    -webkit-transition: -webkit-transform 0.3s linear;

}




#wrapper ul li

{

    float:left;

}

<!DOCTYPE html>

<html>

<head>

<title>Swipe Gesture - Gallery</title>

<meta name="apple-mobile-web-app-capable" content="yes" />

<meta name="viewport" content="initial-scale=1.0; minimum-scale=1.0; maximum-
scale=1.0;" />

<link href="css/styles.css" rel="Stylesheet" />

</head>

<body>

    <div id="wrapper">

     <ul id="slideContainer">

       <li>

          <img src="img/1.jpg" width="100%" height="100%"/>

       </li>

       <li>
<img src="img/2.jpg" width="100%" height="100%" />

     </li>

     <li>

          <img src="img/3.jpg" width="100%" height="100%" />

     </li>

     <li>

          <img src="img/4.jpg" width="100%" height="100%" />

     </li>

     <li>

          <img src="img/5.jpg" width="100%" height="100%"/>

     </li>

     <li>

          <img src="img/6.jpg" width="100%" height="100%"/>

     </li>

     <li>

          <img src="img/7.jpg" width="100%" height="100%"/>

     </li>

    </ul>

  </div>

</body>

<script type="text/javascript" src="js/scripts.js">

</script>

</html>
We have a total of 7 images/slides. You can add as much images/slides as you want and the app will adjust
automatically. This looks pretty simple isn’t it. Now, let’s check the java script code needed for handling all our
interactions in our next part- Part2
Link to desktop version of the demo : http://jbk404.site50.net/html5/mobile/swipey/

Weitere ähnliche Inhalte

Kürzlich hochgeladen

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...Martijn de Jong
 
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
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
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 CVKhem
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
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 Scriptwesley chun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Kürzlich hochgeladen (20)

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...
 
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
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Empfohlen

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Empfohlen (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 1

  • 1. Replicating the Swipe Gesture iPhone Gallery for mobile web– HTML5 – Part 1 http://jbkflex.wordpress.com/2012/01/09/replicating-the-swipe-gesture-iphone-gallery-for-mobile- web-html5-part-1/ In this tutorial we will talk about building up a Swipe Gesture photo gallery for iPhone, iPod using web technologies – HTML5, CSS3 and JavaScript. To begin with, you might have viewed pictures in your iPhone or iPod photo library and may remember how you used to swipe your finger across the screen of your device to view the next or the previous image in the gallery. The same thing we are going to replicate and make a mobile web app. Our app will run full screen on the mobile safari browser so this gives it a native look n feel. The features of this mobile web app replicate the iPhone photo library’s default behaviors, 1. Gently swipe across the screen left or right to view the neighboring images. 2. Flickering of images. Swipe across quickly to view neighboring images. I say it harsh swipe across the screen. 3. Current Image comes back if you do not swipe it enough across the screen. 4. When the beginning or end of the list is reached, no matter how much you swipe the image always comes back. First, view a desktop version of the demo to get a feel, drag your mouse over the picture left or right to view other images and try out the features that I have just talked about (View in web-kit browsers – Chrome or Safari):http://jbk404.site50.net/html5/mobile/swipey/ The same thing we are going to replicate for the mobile device. Now, our app is targeted for mobile web kitbrowsers so it will run even on Android browsers. That’s the good thing about a mobile web app, write once run everywhere. Below we have two images of the app running in my iPod Touch, An image/slide showing up in portrait mode
  • 2. Change of slides when swiping What is a Swipe gesture? When you use your finger to drag on the mobile device’s screen it is called a swipe gesture. It is equivalent of a mouse drag over a desktop browser. Remember that our app is a single touch application and not a multi touch app. Even the default iPhone photo gallery is a single touch app. That means you can use only one finger at a time to operate. Check out this video to get an idea: The basic concept to start with
  • 3. I have a picture above that explains the entire process. We have images placed inside <li> elements which acts as slides and all these <li> elements are placed inside an <ul> element. The <li> elements are laid out horizontally since we are building a horizontal gallery. This can easily be done by using float:left CSS property. <div id="wrapper"> <ul id="panelContainer"> <li> <img src="img/1.jpg" width="100%" height="100%"/> </li> <li> <img src="img/2.jpg" width="100%" height="100%" /> </li> ..... </ul> </div> Now, we basically have to move the <ul> element (our slides container) left or right using CSS3 transition and transformations (Hardware accelerated CSS3 transitions, this makes the animation much smooth) based on the user’s swiping gesture interaction on the device screen. Ofcourse we have the four features that we have talked about earlier and need to keep that in mind. So our transition and movements should follow these features and we will have to code it out accordingly. We will talk about it later. Finally we have all our slides and the container inside a wrapper. The wrapper is a <div> element with overflow:hidden. The wrapper occupies the entire browser screen and acts as a masking element. This ensures that only one slide/image is seen at a time. Preparing the slides As I have already talked about, each image is placed inside a <li> element and let’s consider it to be a slide. So, we place multiple such slides inside an <ul> element which is our slide container (Refer the HTML block above). Normally, in an unordered list the <li> elements are placed vertically. To place the slides horizontally, this is how to do it, #wrapper ul { list-style:none; margin:0;
  • 4. padding:0; -webkit-transition: -webkit-transform 0.3s linear; } #wrapper ul li { float:left; } We have set a float:left to our slides. And to the unordered list – the <ul> element we have set list- style:none,padding and margin to 0. One important thing to note is that for our slides to be placed horizontally we have to set enough width to the slide container (<ul>) so that there is room for all the slides and there is no slide wrapping i.e placing slides in a new line after full width is reached. I will talk about this in the java script part. First, let’s check out the full HTML and CSS needed for our app, body { margin:0; padding:10px; } #wrapper { overflow:hidden; } #wrapper ul { list-style:none;
  • 5. margin:0; padding:0; -webkit-transition: -webkit-transform 0.3s linear; } #wrapper ul li { float:left; } <!DOCTYPE html> <html> <head> <title>Swipe Gesture - Gallery</title> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="viewport" content="initial-scale=1.0; minimum-scale=1.0; maximum- scale=1.0;" /> <link href="css/styles.css" rel="Stylesheet" /> </head> <body> <div id="wrapper"> <ul id="slideContainer"> <li> <img src="img/1.jpg" width="100%" height="100%"/> </li> <li>
  • 6. <img src="img/2.jpg" width="100%" height="100%" /> </li> <li> <img src="img/3.jpg" width="100%" height="100%" /> </li> <li> <img src="img/4.jpg" width="100%" height="100%" /> </li> <li> <img src="img/5.jpg" width="100%" height="100%"/> </li> <li> <img src="img/6.jpg" width="100%" height="100%"/> </li> <li> <img src="img/7.jpg" width="100%" height="100%"/> </li> </ul> </div> </body> <script type="text/javascript" src="js/scripts.js"> </script> </html>
  • 7. We have a total of 7 images/slides. You can add as much images/slides as you want and the app will adjust automatically. This looks pretty simple isn’t it. Now, let’s check the java script code needed for handling all our interactions in our next part- Part2 Link to desktop version of the demo : http://jbk404.site50.net/html5/mobile/swipey/