Last active
July 26, 2018 07:05
-
-
Save Shiti/6401225 to your computer and use it in GitHub Desktop.
AngularJS Lightbox directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.modal { | |
width: 800px; | |
left: 40%; | |
} | |
.lightbox-content { | |
width: 100%; | |
} | |
.lightbox-image { | |
width: 50%; | |
} | |
.lightbox-image img { | |
max-width: 100%; | |
max-height: 100%; | |
} | |
.lightbox-description { | |
width: 50%; | |
} | |
.lightbox-close { | |
position: absolute; | |
left: 95.8%; | |
top: -1%; | |
} | |
.lightbox-prev { | |
top: 50%; | |
position: absolute; | |
} | |
.lightbox-next { | |
top: 50%; | |
position: absolute; | |
left: 93%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="lightbox"> | |
<div class="lightbox-tiles"> | |
<span data-ng-repeat="i in images" data-ng-click="displayImage(i)"> | |
<img width="{{tileWidth}}px" height="{{tileHeight}}px" data-ng-src="{{source(i)}}"> | |
</span> | |
</div> | |
<div modal="showModal"> | |
<div class="lightbox-header"> | |
{{selectedImg.header}} | |
<button class="lightbox-close" data-ng-click="showModal=false;">x</button> | |
</div> | |
<div class="lightbox-content"> | |
<div class="lightbox-image"> | |
<button class="lightbox-prev" data-ng-show="hasPrev()" data-ng-click="prev()">prev</button> | |
<img data-ng-src={{source(selectedImg)}}> | |
</div> | |
<div class="lightbox-description"> | |
{{selectedImg.description}} | |
<button class="lightbox-next" data-ng-show="hasNext()" data-ng-click="next()">next</button> | |
</div> | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var component = angular.module('Components',[]); | |
"use strict"; | |
component.directive('lightbox', function () { | |
return { | |
restrict: 'E', | |
templateUrl: "/assets/templates/lightbox.html", | |
scope: { | |
images: '=' | |
}, | |
replace: true, | |
controller: function ($rootScope, $scope) { | |
$scope.path = "src"; | |
$scope.tileWidth = 150; | |
$scope.tileHeight = 150; | |
$scope.displayImage = function (img) { | |
$scope.selected = $scope.images.indexOf(img); | |
$scope.selectedImg = img; | |
$scope.showModal = true; | |
}; | |
$scope.source = function (img) { | |
return img[$scope.path]; | |
}; | |
$scope.hasPrev = function () { | |
return ($scope.selected !== 0); | |
}; | |
$scope.hasNext = function () { | |
return ($scope.selected < $scope.images.length - 1); | |
}; | |
$scope.next = function () { | |
$scope.selected = $scope.selected + 1; | |
$scope.selectedImg = $scope.images[$scope.selected]; | |
}; | |
$scope.prev = function () { | |
$scope.selected = $scope.selected - 1; | |
$scope.selectedImg = $scope.images[$scope.selected]; | |
}; | |
} | |
}; | |
}); |
@tatsuhirosatou it uses what I'm assuming is an old version of AngularUI's modal directive.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this directive require actual lightbox? Does it require a modal directive?