gpt4 book ai didi

javascript - 如何使用 jquery 创建图片库

转载 作者:太空宇宙 更新时间:2023-11-04 08:46:40 26 4
gpt4 key购买 nike

我有 jquery carousel(cycle2) 和 popup (lightgallery),你会在例子中看到我的轮播,这个例子工作得很好,正如我所期望的那样

$(document).ready(function(){

function generateSlider(){
$('.mySlideShow').cycle({
next: "#single-right",
pauseOnHover: true,
log: false,
pager: "#single-pager",
pagerTemplate: "<a href='#'><img src='{{src}}' width=48 height=48></a>",
prev: "#single-left",
slides: "img[data-hidden='false']"
});
}

generateSlider();


$(".filter li").on("click",function(){
var activeId = $(this).attr("id");
if(activeId == "show-all"){
$("img[data-id]").attr("data-hidden", "false");
} else {
$("img[data-id]").attr("data-hidden", "true");
$("img[data-id = '" + activeId + "']").attr("data-hidden", "false");
}
$('.mySlideShow').cycle('destroy');
generateSlider();
});
});
.single-gallery{
width:800px;
overflow:hidden;
position:relative;
}
.cycle-slideshow img {
width:100%;
height:494px;
max-width:100%;
}

#single-pager a img {
width: 49.3px !important;
height:49.3px !important;
border: 1px solid #fff;
}

#single-pager a.cycle-pager-active img {
opacity: 0.4;
}

#single-left,
#single-right {
position: absolute;
top: 50%;
z-index: 1000;
background: rgba(255, 255, 255, .8);
padding: 12px;
cursor: pointer;
}

#single-left {
left: 0;
}

#single-right {
right: 0;
}

.filter {
position: absolute;
z-index: 1000;
right: 0;
top:0;
padding: 0;
color: #FFF;
background: rgba(255, 255, 255, 0.6);
padding: 10px 30px;
}

.filter li {
list-style-type:none;
cursor: pointer;
display: inline-block;
background: rgba(0, 0, 0, .6);
padding: 5px;
}

img[data-hidden="true"]{
display: none;
}
<link href="https://cdn.jsdelivr.net/lightgallery/latest/css/lightgallery.css" rel="stylesheet"/>

<div class="single-gallery">
<div class="mySlideShow">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/golden-wheat-field-lightbox.jpg" data-id="sports" data-hidden="false">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/sunny-day-lightbox.jpg" data-id="naturel" data-hidden="false">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/night-in-the-city-lightbox.jpg" data-id="animals" data-hidden="false">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/sakura%20trees-lightbox.jpg" data-id="animals" data-hidden="false"/>
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/daffodil-flowers-lightbox.jpg" data-id="animals" data-hidden="false"/>
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/dandelion-lightbox.jpg" data-id="animals" data-hidden="false"/>
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/tulips-lightbox.jpg" data-id="sports" data-hidden="false"/>
<div id="single-pager" class="center external"></div>

<div id="single-next-prev">
<span id="single-left">Prev</span>
<span id="single-right">Next</span>
</div>
</div>

<ul class="filter">
<li id="sports">Sports</li>
<li id="naturel">Naturel</li>
<li id="animals">Animals</li>
<li id="show-all">All</li>
</ul>
</div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.cycle2/2.1.6/jquery.cycle2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.3.9/js/lightgallery.min.js"></script>

但是如果我用 a 包装我的 èach 图像,那么我的过滤就不会像您在示例中看到的那样工作 - please click to see example

我想知道我的代码有什么问题吗?

最佳答案

好的,寻呼机搞砸了,但这是我得到的:

  • 更改 slides:"a[data-hidden='false']"
  • 替换 img 的每个实例至 a.click功能。
  • img[data-hidden="true"]{ display: none; to } `a[data-hidden="true"]{ 显示:无;到
  • 替换pagerTemplate: "<a href='#'><img src='{{src}}' width=48 height=48></a>"pagerTemplate: "<a href='#'><img src='{{children.0.src}}' width=48 height=48></a>"

$(document).ready(function() {
function generateSlider() {
$(".mySlideShow").cycle({
next: "#single-right",
log: false,
fx: "fade",
caption: ".cycle-caption",
captionTemplate: "{{title}}",
pauseOnHover: true,
pager: "#single-pager",
pagerTemplate: "<a href='#'><img src='{{children.0.src}}' width=60 height=60></a>",
prev: "#single-left",
slides: "a[data-hidden='false']"
});
}

generateSlider();

$(".filter li").on("click", function() {
var activeId = $(this).attr("id");
if (activeId == "show-all") {
$("a").attr("data-hidden", "false");
} else {
$("a").attr("data-hidden", "true");
$("a[data-id = '" + activeId + "']").attr("data-hidden", "false");
}
$(".mySlideShow").cycle("destroy");
generateSlider();
});

$(" .mySlideShow").lightGallery({
exThumbImage: "data-exthumbimage",
download: false,
thumbnail: true,
loadYoutubeThumbnail: true,
youtubeThumbSize: "default",
loadVimeoThumbnail: true,
vimeoThumbSize: "thumbnail_medium"
});
});
.single-gallery {
width: 800px;
overflow: hidden;
position: relative;
}

.cycle-slideshow img {
width: 100%;
height: 494px;
max-width: 100%;
}

#single-pager a img {
width: 49.3px !important;
height: 49.3px !important;
border: 1px solid #fff;
}

#single-pager a.cycle-pager-active img {
opacity: 0.4;
}

#single-left,
#single-right {
position: absolute;
top: 50%;
z-index: 1000;
background: rgba(255, 255, 255, .8);
padding: 12px;
cursor: pointer;
}

#single-left {
left: 0;
}

#single-right {
right: 0;
}

.filter {
position: absolute;
z-index: 1000;
right: 0;
top: 0;
padding: 0;
color: #FFF;
background: rgba(255, 255, 255, 0.6);
padding: 10px 30px;
}

.filter li {
list-style-type: none;
cursor: pointer;
display: inline-block;
background: rgba(0, 0, 0, .6);
padding: 5px;
}

a[data-hidden="true"] {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/lightgallery/latest/css/lightgallery.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.cycle2/2.1.6/jquery.cycle2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.3.9/js/lightgallery.min.js"></script>


<div class="single-gallery" id="single-gallery">
<div class="single-gallery-carousel">
<div class="slideshow-area">
<ul class="filter">
<li id="sports">Sports</li>
<li id="naturel">Naturel</li>
<li id="animals">Animals</li>
<li id="show-all">All</li>
</ul>
</div>
<div class="mySlideShow">
<a data-exthumbimage="http://cdn.anitur.com.tr/resimler/normal/2014-02/tur_kuba_CP62I36hoYGMpFFRiN78.jpg" data-id="naturel" data-hidden="false" data-src="http://cdn.anitur.com.tr/resimler/normal/2014-02/tur_kuba_CP62I36hoYGMpFFRiN78.jpg">
<img src="https://sachinchoolur.github.io/lightGallery/static/img/12.jpg">
</a>

<a class="video" data-hidden="false" data-id="naturel" data-src="http://nerdist.com/wp-content/uploads/2016/06/The-Evolution-of-Pixar.jpg" href="https://vimeo.com/1084537">
<img src="http://nerdist.com/wp-content/uploads/2016/06/The-Evolution-of-Pixar.jpg">
</a>

<a data-exthumbimage="http://betacontent.anitur.com.tr/web/images/h494/2017-03/otel_aurum-didyma-spa-beach-resort_sReNOBXcinbZI7lNGf3x.jpg" data-hidden="false" data-id="naturel" data-src="http://betacontent.anitur.com.tr/web/images/h494/2017-03/otel_aurum-didyma-spa-beach-resort_sReNOBXcinbZI7lNGf3x.jpg">
<img src="http://betacontent.anitur.com.tr/web/images/h494/2017-03/otel_aurum-didyma-spa-beach-resort_sReNOBXcinbZI7lNGf3x.jpg">
</a>

<a data-exthumbimage="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/tulips-lightbox.jpg" data-hidden="false" data-id="animals" data-src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/tulips-lightbox.jpg">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/tulips-lightbox.jpg">
</a>

<a data-exthumbimage="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/golden-wheat-field-lightbox.jpg" data-hidden="false" data-id="sports" data-src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/golden-wheat-field-lightbox.jpg">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/golden-wheat-field-lightbox.jpg"></a>

<a data-exthumbimage="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/night-in-the-city-lightbox.jpg" data-hidden="false" data-id="sports" data-src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/night-in-the-city-lightbox.jpg">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/night-in-the-city-lightbox.jpg"></a>

<a data-exthumbimage="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/night-in-the-city-lightbox.jpg" data-hidden="false" data-id="sports" data-src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/night-in-the-city-lightbox.jpg">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/night-in-the-city-lightbox.jpg"></a>

<a data-exthumbimage="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/dandelion-lightbox.jpg" data-hidden="false" data-id="animals" data-src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/dandelion-lightbox.jpg">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/dandelion-lightbox.jpg">
</a>

<a data-exthumbimage="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/daffodil-flowers-lightbox.jpg" data-hidden="false" data-id="sports" data-src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/daffodil-flowers-lightbox.jpg">
<img src="https://amazingcarousel.com/wp-content/uploads/amazingcarousel/7/images/lightbox/daffodil-flowers-lightbox.jpg">
</a>

</div>
</div>
<div class="center external" id="single-pager">
</div>
</div>
<div id="single-next-prev">
<span class="ani-icon-chevron-pointing-to-the-left ani-cycle-control" id="single-left"></span> <span class="ani-icon-right-chevron ani-cycle-control" id="single-right"></span>
</div>
</div>

CodePen

关于javascript - 如何使用 jquery 创建图片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43725809/

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