此jquery代码不起作用。
当我单击下一个或上一个导航时,我想淡化内容部分并向上滑动图像。
但不希望所有幻灯片消失。 包括所有文件。
包含的文件: jQuery文件 Bootstrap CSS Bootstrap Js
我尝试了很多次。
$(document).ready(function() {
$('#demo').bind('slide.bs.carousel', function(e) {
$('.carousel-item .content').fadeOut();
$('img').slideUp();
});
$('#demo').bind('slid', function(e) {
$('.carousel-item.active .content').fadeIn();
$('img').sildeUp();
});
});
img {
width: 100%;
}
.carousel {
background-color: #ddd;
}
.thumb {
width: 100px;
height: 100px;
opacity: .8;
position: absolute;
bottom: 50px;
left: -50px;
}
.thumb img {
height: 100%;
width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div id="demo" class="carousel " data-ride="carousel">
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<div class="row">
<div class="content col-lg-6">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
<div class="col-lg-6">
<img src="https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg">
<div class="thumb">
<img src="http://www.tonibest.com/cdn/25/1992/629/download-free-youtube-logo_176010.jpg">
</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row">
<div class="content col-lg-6">
<p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here,
content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy.
Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>
</div>
<div class="col-lg-6">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRZljhs-8w_yC4ZDLRmE9jnqbnaohkHiyTpXcwcjVwy0vA2VpID">
<div class="thumb">
<img src="https://ksr-ugc.imgix.net/assets/011/118/399/3eee3106ac240bd35e56017a75a49be0_original.png?ixlib=rb-1.1.0&w=700&fit=max&v=1462546261&auto=format&frame=1&q=92&s=b330aea947831fdfe3a4e1fe235147bb">
</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row">
<div class="content col-lg-6">
<p>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from
a line in section 1.10.32.
</p>
</div>
<div class="col-lg-6">
<img src="https://wallpaperbrowse.com/media/images/soap-bubble-1958650_960_720.jpg">
<div class="thumb">
<img src="https://cdn.vox-cdn.com/thumbor/o5YGpoRPaflraEPTD1nOCOm8o2k=/0x0:2040x1360/1200x800/filters:focal(857x517:1183x843)/cdn.vox-cdn.com/uploads/chorus_image/image/60142401/acastro_180403_1777_youtube_0001.0.jpg">
</div>
</div>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
任何人的帮助!
答案 0 :(得分:0)
slid.bs.carousel
不仅slid
为避免竞争状况,还添加了仅对完成事件进行滑动的操作。
$(document).ready(function() {
$('#demo').bind('slid.bs.carousel', function(e) {
$('.carousel-item.active .content').fadeOut().delay(300).fadeIn(500);
$('.carousel-item.active img').slideUp().delay(300).fadeIn(500);
});
});