SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
Angular.js & Hammer.js
Team
Clayton Canyon
The Challenge:
Create a native like gesture experience for mobile web
applications and cordova phonegap.
Specifically, we were interested in delivering gestures
as angular directives.
Oh, also we are totes javascript noobs.
Hammer.js
A powerful and somewhat documented library for
handling gesture events.
Getting Started
Add Hammer.js and Modernizr
Add some of this meta
<meta name="viewport" content="user-scalable=no, width=device-
width, initial-scale=1, maximum-scale=1", minimal-ui>
Simple Triggers
Easy Hammer
Hammer(el).on("swipeleft", function() {
alert('you swiped left!');
});
Angular-Gestures makes this a bit easier by providing simple bindings like:
hm-swipeleft=”showCoolStuffOnTheRight()” hm-swipeleft-opts=”
minimum-touch=”3”
Our Solution
We created our own directive.
<ui-gesture>
3 main parts make it work...
1. Hammertime
Create a new instance of hammer and tell it which
events to listen for.
$scope.hammertime.on("dragdown dragup release", function(ev) {
$scope.renderHammer(ev);
});
also: hammertime.off(gestures) and hammertime.enable(toggle)
2. Switch(ev.type)
Set event logic by case - like breakpoint behavior for releases and more!
case "release":
if($scope.draggedDown) {
// over the breakpoint, trigger the callback
if(ev.gesture.deltaY >= $scope.breakpoint) {
$scope.container.className = 'animating';
$scope.setHeight($scope.targetHeight);
$scope.opened = true;
3. Recursion for animation
As you change ev.gesture.deltaY ...
$scope.updateHeight = function() {
$scope.setHeight($scope.slidedown_height);
$scope.anim = requestAnimationFrame(function() {
$scope.updateHeight();
});
};
$scope.setHeight = function(height) {
if(Modernizr.csstransforms3d) {
this.container.style.transform = 'translate3d(0,'+height+'px,0) ';
Important tips
ev.prevent_defaults()
Stops the browsers default behavior. A must for vertical gestures.
ev.stopPropogation()
Prevents Bubble up, so you can nest gestures.
requestAnimationFrame()
Makes sure your sh*t is performant and your battery life is straight all the time m*th#$ f^!&#@
http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
Angular.js & Hammer.js
demo:
http://tinyurl.com/p96pl7v

Weitere ähnliche Inhalte

Ähnlich wie Angular.js & hammer.js - Clayton Meador & Canyon Boak

2011 py con
2011 py con2011 py con
2011 py conEing Ong
 
2010 bb dev con
2010 bb dev con 2010 bb dev con
2010 bb dev con Eing Ong
 
The Death of a Mouse
The Death of a MouseThe Death of a Mouse
The Death of a MouseGeert Bevin
 
YUI for Mobile - HTML5DevConf 11
YUI for Mobile - HTML5DevConf 11YUI for Mobile - HTML5DevConf 11
YUI for Mobile - HTML5DevConf 11Gonzalo Cordero
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineRicardo Silva
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS introdizabl
 
Asynchronous Programming with JavaScript
Asynchronous Programming with JavaScriptAsynchronous Programming with JavaScript
Asynchronous Programming with JavaScriptWebF
 
T 0230 Google Wave Powered By Gwt
T 0230 Google Wave Powered By GwtT 0230 Google Wave Powered By Gwt
T 0230 Google Wave Powered By Gwtsupertoy2015
 
Accelerometer and Open GL
Accelerometer and Open GLAccelerometer and Open GL
Accelerometer and Open GLJohn Wilker
 
Accelerometer and OpenGL
Accelerometer and OpenGLAccelerometer and OpenGL
Accelerometer and OpenGLJohn Wilker
 
An Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptAn Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptPeter-Paul Koch
 
Sufan presentation
Sufan presentationSufan presentation
Sufan presentationSufanhk
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureSimon Willison
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsRomain Guy
 
Extending Ajax Events for all mankind
Extending Ajax Events for all mankindExtending Ajax Events for all mankind
Extending Ajax Events for all mankindKyle Simpson
 
Mobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScriptMobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScriptfranksvalli
 

Ähnlich wie Angular.js & hammer.js - Clayton Meador & Canyon Boak (20)

2011 py con
2011 py con2011 py con
2011 py con
 
2010 bb dev con
2010 bb dev con 2010 bb dev con
2010 bb dev con
 
The Death of a Mouse
The Death of a MouseThe Death of a Mouse
The Death of a Mouse
 
Mobile optimization
Mobile optimizationMobile optimization
Mobile optimization
 
Loadrunner
LoadrunnerLoadrunner
Loadrunner
 
Lecture 3 Javascript1
Lecture 3  Javascript1Lecture 3  Javascript1
Lecture 3 Javascript1
 
YUI for Mobile - HTML5DevConf 11
YUI for Mobile - HTML5DevConf 11YUI for Mobile - HTML5DevConf 11
YUI for Mobile - HTML5DevConf 11
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
 
Asynchronous Programming with JavaScript
Asynchronous Programming with JavaScriptAsynchronous Programming with JavaScript
Asynchronous Programming with JavaScript
 
T 0230 Google Wave Powered By Gwt
T 0230 Google Wave Powered By GwtT 0230 Google Wave Powered By Gwt
T 0230 Google Wave Powered By Gwt
 
Accelerometer and Open GL
Accelerometer and Open GLAccelerometer and Open GL
Accelerometer and Open GL
 
Accelerometer and OpenGL
Accelerometer and OpenGLAccelerometer and OpenGL
Accelerometer and OpenGL
 
An Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptAn Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScript
 
Sufan presentation
Sufan presentationSufan presentation
Sufan presentation
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb Highlights
 
Angular animate
Angular animateAngular animate
Angular animate
 
Extending Ajax Events for all mankind
Extending Ajax Events for all mankindExtending Ajax Events for all mankind
Extending Ajax Events for all mankind
 
Mobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScriptMobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScript
 

Kürzlich hochgeladen

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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
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...apidays
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
[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
 
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
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Kürzlich hochgeladen (20)

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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
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...
 
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...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[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
 
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)
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Angular.js & hammer.js - Clayton Meador & Canyon Boak

  • 3. The Challenge: Create a native like gesture experience for mobile web applications and cordova phonegap. Specifically, we were interested in delivering gestures as angular directives. Oh, also we are totes javascript noobs.
  • 4. Hammer.js A powerful and somewhat documented library for handling gesture events.
  • 5. Getting Started Add Hammer.js and Modernizr Add some of this meta <meta name="viewport" content="user-scalable=no, width=device- width, initial-scale=1, maximum-scale=1", minimal-ui>
  • 6. Simple Triggers Easy Hammer Hammer(el).on("swipeleft", function() { alert('you swiped left!'); }); Angular-Gestures makes this a bit easier by providing simple bindings like: hm-swipeleft=”showCoolStuffOnTheRight()” hm-swipeleft-opts=” minimum-touch=”3”
  • 7. Our Solution We created our own directive. <ui-gesture> 3 main parts make it work...
  • 8. 1. Hammertime Create a new instance of hammer and tell it which events to listen for. $scope.hammertime.on("dragdown dragup release", function(ev) { $scope.renderHammer(ev); }); also: hammertime.off(gestures) and hammertime.enable(toggle)
  • 9. 2. Switch(ev.type) Set event logic by case - like breakpoint behavior for releases and more! case "release": if($scope.draggedDown) { // over the breakpoint, trigger the callback if(ev.gesture.deltaY >= $scope.breakpoint) { $scope.container.className = 'animating'; $scope.setHeight($scope.targetHeight); $scope.opened = true;
  • 10. 3. Recursion for animation As you change ev.gesture.deltaY ... $scope.updateHeight = function() { $scope.setHeight($scope.slidedown_height); $scope.anim = requestAnimationFrame(function() { $scope.updateHeight(); }); }; $scope.setHeight = function(height) { if(Modernizr.csstransforms3d) { this.container.style.transform = 'translate3d(0,'+height+'px,0) ';
  • 11. Important tips ev.prevent_defaults() Stops the browsers default behavior. A must for vertical gestures. ev.stopPropogation() Prevents Bubble up, so you can nest gestures. requestAnimationFrame() Makes sure your sh*t is performant and your battery life is straight all the time m*th#$ f^!&#@ http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/