gpt4 book ai didi

twitter-bootstrap - Bootstrap 轮播延迟加载

转载 作者:行者123 更新时间:2023-12-04 01:52:08 25 4
gpt4 key购买 nike

我正在尝试让 Bootstrap 轮播延迟加载。看起来这应该是直截了当的,但我什至没有在这里遇到任何错误来进行故障排除。 JS:

<script type="text/javascript">
$('#bigCarousel').on("slid", function() {
// load the next image after the current one slid
var $nextImage = $('.active.item', this).next('.item').find('img');
$nextImage.attr('src', $nextImage.data('lazy-load-src'));
});

</script>

然后是html:
<div id="bigCarousel" class="carousel slide">
<div class="carousel-inner">
<div class="active item">
<img src="assets/bigimage1.jpg" class="img-big">
</div>
<div class="item">
<img data-lazy-load-src="assets/menu-header2.jpg" class="img-big">
</div>
</div>
</div>

firebug 中没有 JS 错误或我能弄清楚的任何其他错误,但我的图像没有加载。可能这里有些愚蠢的简单...

最佳答案

最简单的解决方案是:

<div id="carousel" class="carousel slide lazy-load" data-ride="carousel" data-interval="false">
<div class="carousel-inner">
<div class="item active"><img src="image1.jpg"></div>
<div class="item"><img data-src="image2.jpg"></div>
<div class="item"><img data-src="image3.jpg"></div>
</div>
<!-- controls -->
<ol class="carousel-indicators">
<li data-target="#carousel" data-slide-to="0" class="active"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="2"></li>
</ol>
</div>

<script>
$(function() {
$('.carousel.lazy-load').bind('slide.bs.carousel', function (e) {
var image = $(e.relatedTarget).find('img[data-src]');
image.attr('src', image.data('src'));
image.removeAttr('data-src');
});
});
</script>

而已!

关于twitter-bootstrap - Bootstrap 轮播延迟加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12697216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com