使用angularjs和bootstrap创建动态图像库
我如何创建一个动态图像库,使用angularjs和bootstrap显示缩略图,在加载时动态添加图像。它也应该适合手机、台式机和平板电脑。首先确保使用angularjs和bootstrap创建动态图像库,angularjs,twitter-bootstrap,jquery-ui,html5-canvas,Angularjs,Twitter Bootstrap,Jquery Ui,Html5 Canvas,我如何创建一个动态图像库,使用angularjs和bootstrap显示缩略图,在加载时动态添加图像。它也应该适合手机、台式机和平板电脑。首先确保jQuery和AngularJS都是通过script标签加载的。必须首先加载jQuery,因为Angular使用jQuery <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script> <script src="htt
jQuery
和AngularJS
都是通过script
标签加载的。必须首先加载jQuery,因为Angular使用jQuery
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
JavaScript
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope) {
$scope.images = [
{ "src": "image1.png", "alt": "First Image" },
{ "src": "image2.png", "alt": "Second image" },
{ "src": "image3.png", "alt": "Third image" },
{ "src": "image4.png", "alt": "Fourth image" }
];
}]);
希望这有帮助。
使用AngularJS、css和html,您可以简单地做到这一点
HTML
角度画廊
安格拉斯
angular.module('gallery', [])
.controller('GalleryCtrl', ['$scope', function($scope) {
$scope.pictures = [
{name:"first",
img:"http://placehold.it/200?text=first"
},
{name:"second",
img:"http://placehold.it/200?text=second"},
{name:"third",
img:"http://placehold.it/200?text=third"},
{name:"fourth",
img:"http://placehold.it/200?text=fourth"},
{name:"fifth",
img:"http://placehold.it/200?text=fifth"},
{name:"sixth",
img:"http://placehold.it/200?text=sixth"},
{name:"seventh",
img:"http://placehold.it/200?text=seventh"},
{name:"eighth",
img:"http://placehold.it/200?text=eighth"},
]
}])
.directive('gallery', function() {
return {
replace: true,
restrict: 'E',
controller: 'GalleryCtrl',
template: '\
<div class="gallery">\
<div class="picture" ng-repeat="picture in pictures">\
<img src="{{ picture.img }}">\
</div>\
</div>'
}
});
angular.module('gallery',[])
.controller('GalleryCtrl',['$scope',函数($scope){
$scope.pictures=[
{名称:“第一”,
img:“http://placehold.it/200?text=first"
},
{名称:“第二”,
img:“http://placehold.it/200?text=second"},
{名称:“第三”,
img:“http://placehold.it/200?text=third"},
{名称:“第四”,
img:“http://placehold.it/200?text=fourth"},
{名称:“第五”,
img:“http://placehold.it/200?text=fifth"},
{名称:“第六”,
img:“http://placehold.it/200?text=sixth"},
{名称:“第七”,
img:“http://placehold.it/200?text=seventh"},
{名称:“第八”,
img:“http://placehold.it/200?text=eighth"},
]
}])
.directive('gallery',function(){
返回{
替换:正确,
限制:'E',
控制器:“GalleryCtrl”,
模板:'\
\
\
\
\
'
}
});
<h1>angular gallery</h1>
<div ng-app="gallery">
<div ng-controller="GalleryCtrl"><gallery></gallery></div>
</div>
angular.module('gallery', [])
.controller('GalleryCtrl', ['$scope', function($scope) {
$scope.pictures = [
{name:"first",
img:"http://placehold.it/200?text=first"
},
{name:"second",
img:"http://placehold.it/200?text=second"},
{name:"third",
img:"http://placehold.it/200?text=third"},
{name:"fourth",
img:"http://placehold.it/200?text=fourth"},
{name:"fifth",
img:"http://placehold.it/200?text=fifth"},
{name:"sixth",
img:"http://placehold.it/200?text=sixth"},
{name:"seventh",
img:"http://placehold.it/200?text=seventh"},
{name:"eighth",
img:"http://placehold.it/200?text=eighth"},
]
}])
.directive('gallery', function() {
return {
replace: true,
restrict: 'E',
controller: 'GalleryCtrl',
template: '\
<div class="gallery">\
<div class="picture" ng-repeat="picture in pictures">\
<img src="{{ picture.img }}">\
</div>\
</div>'
}
});