我使用css创建了一个响应式图像滑块。我是通过使用这个例子http://bootsnipp.com/snippets/featured/responsive-thumb-preview-in-carousel-indicators来做到的。滑块自动工作,除非我点击旋转木马,而不是滑动图像,它会转到另一页。怎么阻止这个?是因为它与angularjs相冲突吗?
这里是代码:
<div id="thumbnail-preview-indicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#thumbnail-preview-indicators" data-slide-to="0" class="active">
<div class="thumbnail">
<img class="img-responsive" src="../assets/images/abstract_wallpaper_1.png" />
</div>
</li>
<li data-target="#thumbnail-preview-indicators" data-slide-to="1">
<div class="thumbnail">
<img class="img-responsive" src="../assets/images/435523.jpg" />
</div>
</li>
<li data-target="#thumbnail-preview-indicators" data-slide-to="2">
<div class="thumbnail">
<img class="img-responsive" src="../assets/images/wallpaper-1356336.jpg" />
</div>
</li>
</ol>
<div class="carousel-inner">
<div class="item slides active">
<div class="slide-1"></div>
<div class="container">
<div class="carousel-caption">
<h1>Hi there! How was your day?</h1>
<p>This is the slide 1. Next --></p>
<p><a class="btn btn-lg btn-primary" href="#/" role="button">I'm Fine</a></p>
</div>
</div>
</div>
<div class="item slides">
<div class="slide-2"></div>
<div class="container">
<div class="carousel-caption">
<h1>Welcome back! how do you do?</h1>
<p>This is slide 2. Moving on... </p>
<p><a class="btn btn-lg btn-primary" href="#/" role="button">Great! Thanks.</a></p>
</div>
</div>
</div>
<div class="item slides">
<div class="slide-3"></div>
<div class="container">
<div class="carousel-caption">
<h1>You are back again! Need anything?</h1>
<p>This is slide 3. And the last one</p>
<p><a class="btn btn-lg btn-primary" href="#/" role="button">Yes peace :)</a></p>
</div>
</div>
</div>
</div>
<a class="left carousel-control" href="#thumbnail-preview-indicators" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#thumbnail-preview-indicators" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
这是app.js。
'use strict'
var app = angular.module('myWeb',
[
'ngRoute'
]);
console.log('app');
app.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
$routeProvider
.when('/',{
templateUrl: 'home.html',
controller: 'HomeController'
});
$routeProvider
.when('/signup',{
templateUrl: 'signup.html',
controller: 'SignupController'
});
$routeProvider
.when('/contact', {
templateUrl: 'contact.html',
controller: 'ContactController'
});
$routeProvider
.when('/about',{
templateUrl: 'about.html',
controller: 'aboutController'
});
$routeProvider
.when('/t-and-c-m',
{
activatetab: '#t-and-c-m'
});
}]);
我是否还需要配置angularjs,以解决这个问题?感谢帮助,因为我是angularjs的初学者。
问题的CSS如下
#thumbnail-preview-indicators {
position: relative;
overflow: hidden;
}
#thumbnail-preview-indicators .slides .slide-1,
#thumbnail-preview-indicators .slides .slide-2,
#thumbnail-preview-indicators .slides .slide-3 {
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
}
#thumbnail-preview-indicators,
#thumbnail-preview-indicators .slides,
#thumbnail-preview-indicators .slides .slide-1,
#thumbnail-preview-indicators .slides .slide-2,
#thumbnail-preview-indicators .slides .slide-3 {
height: 480px;
}
#thumbnail-preview-indicators .slides .slide-1{
background-image: url(../assets/images/abstract_wallpaper_1.png);
}
#thumbnail-preview-indicators .slides .slide-2{
background-image: url(../assets/images/435523.jpg);
}
#thumbnail-preview-indicators .slides .slide-3{
background-image:url(../assets/images/wallpaper-1356336.jpg);
}
#thumbnail-preview-indicators .carousel-inner .item .carousel-caption {
top: 20%;
bottom: inherit;
}
#thumbnail-preview-indicators .carousel-indicators li,
#thumbnail-preview-indicators .carousel-indicators li.active {
position: relative;
width: 100px;
height: 8px;
}
#thumbnail-preview-indicators .carousel-indicators li > .thumbnail {
position: absolute;
top: 0;
width: 100px;
display: none;
opacity: 0;
left: 50%;
margin-top: -80px;
margin-left: -50px;
}
#thumbnail-preview-indicators .carousel-indicators li:hover > .thumbnail,
#thumbnail-preview-indicators .carousel-indicators li.active > .thumbnail {
display: block;
opacity: .8;
}
#thumbnail-preview-indicators .carousel-indicators li.active > .thumbnail:hover{
opacity: 1;
}
@media screen and (max-width : 480px) {
#thumbnail-preview-indicators .carousel-indicators li,
#thumbnail-preview-indicators .carousel-indicators li.active {
width: 50px;
height: 8px;
position: relative;
}
#thumbnail-preview-indicators .carousel-indicators li > .thumbnail {
width: 50px;
left: 50%;
margin-top: -50px;
margin-left: -25px;
}
}
答案 0 :(得分:2)
Bootstrap Carousel与AngularJs不兼容,因为他们在next / prev按钮中使用了#。
您可以尝试重写carousel.js的引导代码,也可以使用其他类似的项目: https://angular-ui.github.io/bootstrap/
答案 1 :(得分:0)
在我看来,你有足够的<a href='#/'>
点击它们确实会加载一个新页面。这里有什么意图?最有可能的是,您希望ng-click="myfunc()"
具有声明
$scope.myfunc = function() {....}
在用户点击链接时执行其他操作。该声明将在控制器中为页面的该部分完成(我将在CarouselController
的第一个div上专门设置ng-controller="CarouselController
,以便您可以在其他地方重用它(如果需要)