<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app="app">
<div class="container" ng-controller="MainController as main">
<div class="column" ng-repeat="column in main.columns">
<div ng-repeat="image in column.images">
<img load src="{{image}}" alt="img" />
</div>
</div>
</div>
</body>
</html>
.container {
width: 600px;
}
.column {
display: block;
width:200px;
float: left;
}
(function() {
angular
.module('app', [])
.controller('MainController', MainController)
.service('columnsService', columnsService)
.directive('load', loadDirective);
function MainController($scope, columnsService) {
var vm = this;
vm.columns = columnsService.columns;
columnsService.init([
'http://www.myschool21.narod.ru/mountain/images/fr_1041.jpg',
'http://wallpaperscraft.ru/image/92232/200x300.jpg?orig=3',
'http://cs10573.vk.me/g24449285/a_e2f12ad0.jpg',
'http://static2.gooddays.ru/photos/0002/6209/andorra_preview.jpg?1241084584',
'http://www.comunicom.ru/images/stories/PHOTO-2013/MINI/3.jpg'
]);
}
function columnsService() {
var service = {
images: [],
columnsCount: 3,
columns: [],
init: init,
initColumns: initColumns,
pushNextImage: pushNextImage,
getLowestColumn: getLowestColumn,
updateColumn: updateColumn
};
return service;
function init(images) {
service.images = images;
service.initColumns();
service.pushNextImage();
}
function initColumns() {
for (var i = 0; i < service.columnsCount; i++) {
service.columns[i] = {
height: 0,
images: []
};
}
}
function pushNextImage() {
var image = service.images.shift();
if (image) {
var column = service.getLowestColumn();
column.images.push(image);
}
}
function getLowestColumn() {
var minIndex = null;
var minHeight = null;
angular.forEach(service.columns, function(column, index) {
if (minIndex === null || column.height < minHeight) {
minIndex = index;
minHeight = column.height;
}
});
return service.columns[minIndex];
}
function updateColumn(index, height) {
service.columns[index].height += height;
}
}
function loadDirective(columnsService) {
var directive = {
restrict: 'A',
link: link
};
return directive;
function link($scope, element, attrs) {
element.on('load', function(event) {
$scope.$apply(function() {
columnsService.updateColumn($scope.$parent.$index, element[0].offsetHeight);
columnsService.pushNextImage();
});
});
}
}
})();
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |