我正在使用Photoswipe来创建图像库。但是当一些图片关闭(即你在图片外面点击时)时,我无法制作动画效果。我希望它看起来像这个例子:
现在,它会抛出错误:
我正在使用自定义代码。我已经修改了代码,我的整个代码如下:(请看到注释中的“animation”-这是我需要做的部分)
现在,它会抛出错误:
TypeError: thumbnail.getBoundingClientRect不是一个函数
$(document).ready(function() {
$('.my-gallery').each( function() {
var $pic = $(this),
getItems = function() {
var items = [];
$pic.find('a').each(function() {
var $width = $(this).data('width');
var $height = $(this).data('height');
var $href = $(this).data('src'),
// $size = $(this).data('size').split('x'),
$width = $width ,
$height = $height;
var item = {
src : $href,
w : $width,
h : $height
}
items.push(item);
// alert($height);
});
return items;
}
var items = getItems();
var $pswp = $('.pswp')[0];
$pic.on('click', '.pic-gallery', function(event) {
event.preventDefault();
var $index = $(this).index();
// alert($index);
var options = {
index: $index,
bgOpacity: 0.7,
showHideOpacity: true,
// fadeOutSpeed:100,
enableMouseWheel: false, enableKeyboard: false,
showHideOpacity:true, getThumbBoundsFn:false,
//animation
getThumbBoundsFn: function(index) {
$pic.find('a').each(function() {
var thumbnail = $(this).data('src');
var pageYScroll = window.pageYOffset || document.documentElement.scrollTop;
var rect = thumbnail.getBoundingClientRect();
return {x: rect.left, y: rect.top + pageYScroll, w: rect.width};
});
//end animation
}
var lightBox = new PhotoSwipe($pswp, PhotoSwipeUI_Default, items, options);
lightBox.init();
});
});
});
<div id="post_gallery" class="my-gallery">
@foreach($gallery as $pic)
<div class="left pic-gallery">
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<?php $img_src = 'myproject.com/'. $pic['path'] .'/'. $pic['filename']; list($width, $height) = getimagesize($img_src);?>
<a itemprop="contentUrl" data-size="{{$width}}x{{$height}}" title="{{ $pic['title'] }}" data-width="{{$width}}" data-height="{{$height}}" data-src="myproject.com/{{ $pic['path'] }}/{{ $pic['filename'] }}" href="myproject.com/{{ $pic['path'] }}/{{ $pic['filename'] }}" rel="bookmark">
<img class="left img-thumbnail" width="100" height="75" src="myproject.com/{{ $pic['path'] }}/thumbs/thumbs_{{ $pic['filename'] }}" alt="thumbnail {{ $pic['title'] }}">
</a>
</figure>
</div>
@endforeach
In examples this is done by using the following:
options = {
// define gallery index (for URL)
galleryUID: galleryElement.getAttribute('data-pswp-uid'),
getThumbBoundsFn: function(index) {
// See Options -> getThumbBoundsFn section of documentation for more info
var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail
pageYScroll = window.pageYOffset || document.documentElement.scrollTop,
rect = thumbnail.getBoundingClientRect();
return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};
}
};