发表于: 2017-05-25 23:28:53

1 1059


今天完成的事:

拆完公共样式:顶部导航和底部信息栏

使用bootstrap自带轮播做首页banner,http请求接口返回数据通过ng-repeat渲染首页banner,

首页banner下面的简介静态页面完成

明天计划的事:

最新职位编写

更多职位编写

伙伴之言编写

遇到的问题:

轮播图一开始准备用angular-ui-bootstrap轮播插件的,dome的时候没有问题,但是在项目中应用时出现各种报错,搞了2个小时,没能搞好;果断放弃,改用bootstrap自带轮播,简单方便。

长时间没写样式了,对bootstrap 和css有点生疏了,用的时候还要现找质料来复习。

收获:

1,通过angular 实现轮播

dome

<div class="container">
<div class="col-lg-8" ng-app="ui.bootstrap.demo">
<div ng-controller="CarouselDemoCtrl">
<div style="height: 305px">
<div uib-carousel active="active" no-transition="false" interval="myInterval" no-wrap="noWrapSlides">
<div uib-slide ng-repeat="slide in slides track by slide.id" index="slide.id">
<img ng-src="{{slide.image}}" style="margin:auto;">
<div class="carousel-caption">
<h4>Slide {{slide.id}}</h4>
<p>{{slide.text}}</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('CarouselDemoCtrl', function ($scope) {
$scope.myInterval = 3000;
$scope.noWrapSlides = false;
$scope.active = 0;
var slides = $scope.slides = [];
var currIndex = 0;

$scope.addSlide = function() {
var newWidth = 600 + slides.length + 1;
slides.push({
image: '//unsplash.it/' + newWidth + '/300',
text: ['Nice image','Awesome photograph','That is so cool','I love that'][slides.length % 4],
id: currIndex++
});
};
$scope.randomize = function() {
var indexes = generateIndexesArray();
assignNewIndexesToSlides(indexes);
};
for (var i = 0; i < 4; i++) {
$scope.addSlide();
}
// Randomize logic below
       function assignNewIndexesToSlides(indexes) {
for (var i = 0, l = slides.length; i < l; i++) {
slides[i].id = indexes.pop();
}
}
function generateIndexesArray() {
var indexes = [];
for (var i = 0; i < currIndex; ++i) {
indexes[i] = i;
}
return shuffle(indexes);
}

// http://stackoverflow.com/questions/962802#962890
       function shuffle(array) {
var tmp, current, top = array.length;

if (top) {
while (--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
}
return array;
}
});
</script>

2,bootstrap自带轮播为了防止与其他JS文件冲突(进入页面后不能自动轮播)需要加代码

<script type="text/javascript">

    // bootstrop轮播防止冲突,进入即轮播.

    $('.carousel').carousel()

</script> 



返回列表 返回列表
评论

    分享到