forked from revolunet/angular-carousel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathangular-panorama.min.js
8 lines (8 loc) · 1.48 KB
/
angular-panorama.min.js
1
2
3
4
5
6
7
8
/**
* Angular Panorama - Mimic Windows Phone's Panorama UI control.
* @version v0.2.0 - 2014-03-18
* @link http://cnjsstong2.github.com/angular-panorama
* @author Tong Shen <tshen@farseerinc.com>
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
angular.module("angular-panorama",["ngTouch"]),angular.module("angular-panorama").directive("ngPanorama",["$swipe",function(a){return{restrict:"A",scope:{pages:"=ngPanorama",i:"=ngPanoramaIndex",bg:"=ngPanoramaBackgroundImage",reset:"=ngPanoramaReset"},link:function(b,c){function d(a){for(var d=0,e=c.prop("offsetWidth"),f=0;a>f;f++)d-=(b.pages[f].width||100)*e/100;if(a>0){var g=(100-b.pages[a].width)/2*e/100;d+=g,a==b.pages.length-1&&(d+=g)}return parseInt(d,10)}function e(a){f.css({"-webkit-transform":"translate3d("+a+"px, 0, 0)",transform:"translate3d("+a+"px, 0, 0)"})}b.$watch("bg",function(a){a&&c.css("background-image","url("+a+")")}),b.$watch("i",function(a){e(d(a))}),b.$watch("reset",function(){f.css(j),e(0),f.css(i)}),c.addClass("ng-panorama-container");var f=c.find("ul");f.addClass("ng-panorama-slides"),b.i||(b.i=0);var g,h,i={transition:"all 0.2s ease","-webkit-transition":"all 0.2s ease"},j={transition:"none","-webkit-transition":"none"};a.bind(c,{start:function(a){g=a,h=d(b.i),f.css(j)},move:function(a){e(h+a.x-g.x)},end:function(a){var h=b.i,j=.1*c.prop("offsetWidth"),k=a.x-g.x;k>j&&h>0?h--:-j>k&&h<b.pages.length-1&&h++,b.$apply(function(){b.i=h}),f.css(i),e(d(b.i))},cancel:function(){f.css(i),e(d(b.i))}})}}}]);