gpt4 book ai didi

javascript - 尝试使用 Jquery 隐藏带分页的缩略图

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:09 24 4
gpt4 key购买 nike

我正在尝试将分页添加到页面底部,允许用户从一组缩略图移动到另一组。该页面是一个画廊页面,用户可以单击左侧的缩略图来更改右侧的幻灯片。

HTML

<div class="container">
<div id="main_area">
<!-- Slider -->
<div class="row">
<div class="col-sm-6" id="slider-thumbs firstpage">
<!-- Bottom switcher of slider -->
<ul class="hide-bullets">
<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-0">
<img src="images/thumbnails/img1.jpg">
</a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-1"><img src="images/thumbnails/img2.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-2"><img src="images/thumbnails/img3.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-3"><img src="images/thumbnails/img4.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-4"><img src="images/thumbnails/img5.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-5"><img src="images/thumbnails/img6.jpg"></a>
</li>
<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-6"><img src="images/thumbnails/img7.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-7"><img src="images/thumbnails/img8.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-8"><img src="images/thumbnails/img9.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-9"><img src="images/thumbnails/img10.jpg"></a>
</li>
<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-10"><img src="images/thumbnails/img11.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-11"><img src="images/thumbnails/img12.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-12"><img src="images/thumbnails/img13.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-13"><img src="images/thumbnails/img14.jpg"></a>
</li>
<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-14"><img src="images/thumbnails/img15.jpg"></a>
</li>

<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-15"><img src="images/thumbnails/img16.jpg"></a>
</li>
<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-16"><img src="images/thumbnails/img17.jpg"></a>
</li>
<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-17"><img src="images/thumbnails/img18.jpg"></a>
</li>
<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-18"><img src="images/thumbnails/img19.jpg"></a>
</li>
<li class="col-sm-3">
<a class="thumbnail page-1" id="carousel-selector-19"><img src="images/thumbnails/img20.jpg"></a>
</li>
<li class="col-sm-3">
<a class="thumbnail page-2 hide-thumbnail" id="carousel-selector-20"><img src="images/thumbnails/img21.jpg"></a>
</li>
</ul>
<nav>
<ul class="pagination">
<li>
<a aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li><a id="pag-1">1</a></li>
<li><a id="pag-1">2</a></li>
<li><a id="pag-3">3</a></li>
<li><a id="pag-4">4</a></li>
<li><a id="pag-5">5</a></li>
<li>
<a aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
</div>

<div class="col-sm-6">
<div class="col-xs-12" id="slider">
<!-- Top part of the slider -->
<div class="row">
<div class="col-sm-12" id="carousel-bounding-box">
<div class="carousel slide" id="myCarousel">
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item" data-slide-number="0">
<img src="images/img1.jpg"></div>

<div class="item" data-slide-number="1">
<img src="images/img2.jpg"></div>

<div class="item" data-slide-number="2">
<img src="images/img3.jpg"></div>

<div class="item" data-slide-number="3">
<img src="images/img4.jpg"></div>

<div class="item" data-slide-number="4">
<img src="images/img5.jpg"></div>

<div class="item" data-slide-number="5">
<img src="images/img6.jpg"></div>

<div class="item" data-slide-number="6">
<img src="images/img7.jpg"></div>

<div class="item" data-slide-number="7">
<img src="images/img8.jpg"></div>

<div class="item" data-slide-number="8">
<img src="images/img9.jpg"></div>

<div class="item" data-slide-number="9">
<img src="images/img10.jpg"></div>

<div class="item" data-slide-number="10">
<img src="images/img11.jpg"></div>

<div class="item" data-slide-number="11">
<img src="images/img12.jpg"></div>

<div class="item" data-slide-number="12">
<img src="images/img13.jpg"></div>

<div class="item" data-slide-number="13">
<img src="images/img14.jpg"></div>

<div class="item" data-slide-number="14">
<img src="images/img15.jpg"></div>

<div class="item" data-slide-number="15">
<img src="images/img16.jpg"></div>
<div class="item" data-slide-number="16">
<img src="images/img17.jpg"></div>
<div class="item" data-slide-number="17">
<img src="images/img18.jpg"></div>
<div class="item" data-slide-number="18">
<img src="images/img19.jpg"></div>
<div class="item" data-slide-number="19">
<img src="images/img20.jpg"></div>
<div class="item" data-slide-number="20">
<img src="images/img21.jpg"></div>
</div>
<!-- Carousel nav -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>
</div>
</div>
<!--/Slider-->
</div>

</div>
</div>

CSS

.hide-thumbnail{
display: none;
}

.show-thumbnail{
display: block;
}

Jquery

    <script type="text/javascript">
jQuery(document).ready(function($) {

$('#myCarousel').carousel({
interval: 5000
});

//Handles the carousel thumbnails
$('[id^=carousel-selector-]').click(function () {
var id_selector = $(this).attr("id");
try {
var id = /-(\d+)$/.exec(id_selector)[1];
console.log(id_selector, id);
jQuery('#myCarousel').carousel(parseInt(id));
} catch (e) {
console.log('Regex failed!', e);
}
});
// When the carousel slides, auto update the text
$('#myCarousel').on('slid.bs.carousel', function (e) {
var id = $('.item.active').data('slide-number');
$('#carousel-text').html($('#slide-content-'+id).html());
});
});

function ThumbnailPagination(){
jQuery('#pag-1').live("click", function(){
jQuery('.page-1').removeClass("hide-thumbnail");
jQuery('.page-1').addClass("show-thumbnail");
});
jQuery('#pag-2').live("click", function(){
jQuery('.page-1').removeClass("show-thumbnail");
jQuery('.page-1').addClass("hide-thumbnail");
jQuery('.page-2').removeClass("hide-thumbnail");
jQuery('.page-2').addClass("show-thumbnail");
});
};

</script>

我基本上是想在每个 <a> 时隐藏/显示缩略图单击页码。然而,它通常只工作一次,有时甚至根本不工作。目前只有“1”起作用,“2”甚至什么都不做。

网站链接 Website Link

最佳答案

我的问题已经解决了

HTML

<nav>
<ul class="pagination">
<li>
<a aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li><a id="pag-1">1</a></li>
<li><a id="pag-2">2</a></li>
<li>
<a aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>

JQuery

    $(document).ready(function() {
$('#pag-1').on("click", ThumbnailPagination1);
});
$(document).ready(function() {
$('#pag-2').on("click", ThumbnailPagination2);
});

function ThumbnailPagination1(){
jQuery('.page-1').removeClass("hide-thumbnail");
jQuery('.page-1').addClass("show-thumbnail");
jQuery('.page-2').removeClass("show-thumbnail");
jQuery('.page-2').addClass("hide-thumbnail");
};

function ThumbnailPagination2(){
jQuery('.page-1').removeClass("show-thumbnail");
jQuery('.page-1').addClass("hide-thumbnail");
jQuery('.page-2').removeClass("hide-thumbnail");
jQuery('.page-2').addClass("show-thumbnail");
};

关于javascript - 尝试使用 Jquery 隐藏带分页的缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35708180/

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