在一个项目中滚动会影响 bootstrap 轮播中的另一个项目
Scroll in one item is affecting another item in bootstrap carousel
在我的页面中,我有一个旋转木马和该旋转木马中的四个项目。
所有项目都有一些大列表,在一个项目中滚动会自动滚动其他项目。
我不希望其他项目自动滚动它们应该在它们的位置直到滚动,如何做到这一点?
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 70%;
margin: auto;
}
</style>
</head>
<body>
<div class="container">
<br>
<div id="myCarousel" class="carousel" >
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
</div>
<div class="item">
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
</div>
<div class="item">
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item3</p>
<p>Item 3</p>
<p>Item3</p>
</div>
<div class="item">
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</body>
</html>
这是因为您是在网页上滚动,而不是在轮播中...
这是一种方法,只需要为轮播项目设置一个max-height
。
CSS:
.carousel .item {max-height:300px;overflow:auto;}
Bootply : http://www.bootply.com/c0k8PpJ6PP
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 70%;
margin: auto;
}
.carousel .item {max-height:300px;overflow:auto;}
</style>
</head>
<body>
<div class="container">
<br>
<div id="myCarousel" class="carousel" >
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
</div>
<div class="item">
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
</div>
<div class="item">
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item3</p>
<p>Item 3</p>
<p>Item3</p>
</div>
<div class="item">
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</body>
</html>
在我的页面中,我有一个旋转木马和该旋转木马中的四个项目。
所有项目都有一些大列表,在一个项目中滚动会自动滚动其他项目。
我不希望其他项目自动滚动它们应该在它们的位置直到滚动,如何做到这一点?
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 70%;
margin: auto;
}
</style>
</head>
<body>
<div class="container">
<br>
<div id="myCarousel" class="carousel" >
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
</div>
<div class="item">
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
</div>
<div class="item">
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item3</p>
<p>Item 3</p>
<p>Item3</p>
</div>
<div class="item">
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</body>
</html>
这是因为您是在网页上滚动,而不是在轮播中...
这是一种方法,只需要为轮播项目设置一个max-height
。
CSS:
.carousel .item {max-height:300px;overflow:auto;}
Bootply : http://www.bootply.com/c0k8PpJ6PP
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 70%;
margin: auto;
}
.carousel .item {max-height:300px;overflow:auto;}
</style>
</head>
<body>
<div class="container">
<br>
<div id="myCarousel" class="carousel" >
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
<p>Item 1</p>
</div>
<div class="item">
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item 2</p>
<p>Item2</p>
</div>
<div class="item">
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item 3</p>
<p>Item3</p>
<p>Item 3</p>
<p>Item3</p>
</div>
<div class="item">
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
<p>Item 4</p>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</body>
</html>