与滑块同步的华丽弹出窗口
Magnific pop-up synchronized with slider
只是想知道是否可以将 Magnific 弹出窗口与滑块(例如 flexslider 或 slick)同步,这样当您在 Magnific 弹出窗口上更改幻灯片时,背景中的滑块也会更改。
编辑
$('.slick-slider').magnificPopup({
delegate: '.slides:not(.slick-cloned) a',
type: 'image',
mainClass: 'mfp-fade',
fixedContentPos: false,
removalDelay: 350,
pauseOnHover: false,
gallery:{
enabled: true,
tCounter: '<span class="mfp-counter">%curr% of %total%</span>'
},
callbacks: {
beforeClose: function() {
$('.slick-slider').slick('slickGoTo', parseInt(this.index - 1));
// works better with the code bellow but sometimes gets stuck between 2 slides
$('.slick-slider').slick('slickGoTo', parseInt(this.index));
}
}
});
绝对有可能。这是一个使用 Slick.js.
的示例
HTML
<div class="carousel">
<a href="//satyr.io/1280x720/1"><img src="//satyr.io/600x400/1" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/2"><img src="//satyr.io/600x400/2" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/3"><img src="//satyr.io/600x400/3" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/4"><img src="//satyr.io/600x400/4" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/5"><img src="//satyr.io/600x400/5" width="600" height="400" alt="" /></a>
</div>
JS
$(document).ready(function() {
var $carousel = $('.carousel');
$carousel
.slick()
.magnificPopup({
type: 'image',
delegate: 'a:not(.slick-cloned)',
gallery: {
enabled: true
},
callbacks: {
open: function() {
var current = $carousel.slick('slickCurrentSlide');
$carousel.magnificPopup('goTo', current);
},
beforeClose: function() {
$carousel.slick('slickGoTo', parseInt(this.index));
}
}
});
});
依赖关系
此外,请确保您引入了 jQuery, Slick, and Magnific Popup 的依赖项。
更新
- Slick 创建的克隆项目的帐户
- 在通过键盘导航打开时使用当前幻灯片更新 Magnific Popup
如果您有多个 .carousel 实例,您可以这样做:
https://jsfiddle.net/9dyh2yjt/98/
$(function() {
$('.carousel').each(function() {
var gallery = $(this);
gallery
.slick()
.magnificPopup({
type: 'image',
delegate: 'a:not(.slick-cloned)',
gallery: {
enabled: true
},
callbacks: {
open: function() {
var current = gallery.slick('slickCurrentSlide');
console.log(current);
gallery.magnificPopup('goTo', current);
},
beforeClose: function() {
gallery.slick('slickGoTo', parseInt(this.index));
}
}
});
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
<div class="carousel">
<a href="//satyr.io/1280x720/1"><img src="//satyr.io/600x400/1" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/2"><img src="//satyr.io/600x400/2" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/3"><img src="//satyr.io/600x400/3" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/4"><img src="//satyr.io/600x400/4" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/5"><img src="//satyr.io/600x400/5" width="600" height="400" alt="" /></a>
</div>
<div class="carousel">
<a href="//satyr.io/1280x720/1"><img src="//satyr.io/600x400/1" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/2"><img src="//satyr.io/600x400/2" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/3"><img src="//satyr.io/600x400/3" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/4"><img src="//satyr.io/600x400/4" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/5"><img src="//satyr.io/600x400/5" width="600" height="400" alt="" /></a>
</div>
只是想知道是否可以将 Magnific 弹出窗口与滑块(例如 flexslider 或 slick)同步,这样当您在 Magnific 弹出窗口上更改幻灯片时,背景中的滑块也会更改。
编辑
$('.slick-slider').magnificPopup({
delegate: '.slides:not(.slick-cloned) a',
type: 'image',
mainClass: 'mfp-fade',
fixedContentPos: false,
removalDelay: 350,
pauseOnHover: false,
gallery:{
enabled: true,
tCounter: '<span class="mfp-counter">%curr% of %total%</span>'
},
callbacks: {
beforeClose: function() {
$('.slick-slider').slick('slickGoTo', parseInt(this.index - 1));
// works better with the code bellow but sometimes gets stuck between 2 slides
$('.slick-slider').slick('slickGoTo', parseInt(this.index));
}
}
});
绝对有可能。这是一个使用 Slick.js.
的示例HTML
<div class="carousel">
<a href="//satyr.io/1280x720/1"><img src="//satyr.io/600x400/1" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/2"><img src="//satyr.io/600x400/2" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/3"><img src="//satyr.io/600x400/3" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/4"><img src="//satyr.io/600x400/4" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/5"><img src="//satyr.io/600x400/5" width="600" height="400" alt="" /></a>
</div>
JS
$(document).ready(function() {
var $carousel = $('.carousel');
$carousel
.slick()
.magnificPopup({
type: 'image',
delegate: 'a:not(.slick-cloned)',
gallery: {
enabled: true
},
callbacks: {
open: function() {
var current = $carousel.slick('slickCurrentSlide');
$carousel.magnificPopup('goTo', current);
},
beforeClose: function() {
$carousel.slick('slickGoTo', parseInt(this.index));
}
}
});
});
依赖关系
此外,请确保您引入了 jQuery, Slick, and Magnific Popup 的依赖项。
更新
- Slick 创建的克隆项目的帐户
- 在通过键盘导航打开时使用当前幻灯片更新 Magnific Popup
如果您有多个 .carousel 实例,您可以这样做:
https://jsfiddle.net/9dyh2yjt/98/
$(function() {
$('.carousel').each(function() {
var gallery = $(this);
gallery
.slick()
.magnificPopup({
type: 'image',
delegate: 'a:not(.slick-cloned)',
gallery: {
enabled: true
},
callbacks: {
open: function() {
var current = gallery.slick('slickCurrentSlide');
console.log(current);
gallery.magnificPopup('goTo', current);
},
beforeClose: function() {
gallery.slick('slickGoTo', parseInt(this.index));
}
}
});
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
<div class="carousel">
<a href="//satyr.io/1280x720/1"><img src="//satyr.io/600x400/1" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/2"><img src="//satyr.io/600x400/2" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/3"><img src="//satyr.io/600x400/3" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/4"><img src="//satyr.io/600x400/4" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/5"><img src="//satyr.io/600x400/5" width="600" height="400" alt="" /></a>
</div>
<div class="carousel">
<a href="//satyr.io/1280x720/1"><img src="//satyr.io/600x400/1" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/2"><img src="//satyr.io/600x400/2" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/3"><img src="//satyr.io/600x400/3" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/4"><img src="//satyr.io/600x400/4" width="600" height="400" alt="" /></a>
<a href="//satyr.io/1280x720/5"><img src="//satyr.io/600x400/5" width="600" height="400" alt="" /></a>
</div>