在漫长的学习过程中,会遇到很多问题。在第一次使用angular写项目,自己很慌。不知从何下手。在慢慢摸索中体会到angular给我带来的乐趣,喜爱前端,希望可以一直从事这个行业。利用angular+bootstrap实现轮播图效果。
<!DOCTYPE html>
<html ng-app="myApp" lang="en">
<head>
<meta charset="UTF-8">
<title>AngularJS carousel</title>
<link href="http://libs.baidu.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="CarouselDemoCtrl">
<div style="height: 305px">
<carousel interval="myInterval" no-wrap="noWrapSlides">
<slide ng-repeat="slide in slides" active="slide.active">
<img ng-src="{{slide.image}}" style="margin:auto;width:1000px;height: 600px;"/>
<div class="carousel-caption">
<p>{{slide.text}}</p>
</div>
</slide>
</carousel>
</div>
</div>
<script src="http://apps.bdimg.com/libs/angular.js/1.3.13/angular.min.js"></script>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.0-beta.4/angular-animate.min.js"></script>
<script src="http://cdn.bootcss.com/angular-ui-bootstrap/0.13.3/ui-bootstrap.min.js"></script>
<script src="http://cdn.bootcss.com/angular-ui-bootstrap/0.13.3/ui-bootstrap-tpls.min.js"></script>
<script>
angular.module('myApp', ['ui.bootstrap', 'ngAnimate']).controller('CarouselDemoCtrl', function ($scope) {
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
var slides = $scope.slides = [];
$scope.addSlide = function () {
var newWidth = 600 + slides.length + 1;
slides.push({
image: "img/ban1.jpg",
text: '1',
});
slides.push({
image: 'img/ban2.jpg',
text: '2',
});
slides.push({
image: 'img/ban3.jpg',
text: '3',
});
slides.push({
image: 'img/ban4.jpg',
text: '4',
});
slides.push({
image: 'img/ban22.jpg',
text: '5',
});
slides.push({
image: 'img/ban31.jpg',
text: '6',
});
};
$scope.addSlide();
});
</script>
</body>