我正在使用出色的 Cycle2 插件在我的网站上运行幻灯片,请参见此处: http: //new.element17.com。
幻灯片在为 Cycle2 指定的 div 中生成,如下所示:
<?php
if(isset($_COOKIE["currentalbum"])) {
$currentalbum = $_COOKIE["currentalbum"];
} else {
$currentalbum = "gallery/01_New";
}
$photos = glob($currentalbum.'/*.[Jj][Pp][Gg]');
$albumparts = explode('_', $currentalbum);
switch (array_key_exists(2,$albumparts)) {
case false:
usort($photos,"cmpexiftime");
break;
case true:
usort($photos,"cmpexiftimer");
break;
}
foreach($photos as $photo){
$title = basename($photo,".jpg");
$exif = read_exif_data_raw("$photo",0);
$desc = $exif["IFD0"]["ImageDescription"];
$camera = ucwords(strtolower($exif["IFD0"]["Model"]));
switch($exif["SubIFD"]["LensInfo"]) {
case "105.0 mm f/2.8":
$lens = "Micro-Nikkor 105mm f/2.8 VR";
break;
case "50.0 mm f/1.8":
$lens = "Nikkor 50mm f/1.8D";
break;
case "17.0-50.0 mm f/2.8":
$lens = "Tamron 17-50mm f/2.8 VC";
break;
case "70.0-300.0 mm f/4.5-5.6":
$lens = "Nikkor 70-300mm f/4.5-5.6 VR";
break;
default:
$lens = $exif["SubIFD"]["LensInfo"];
break;
}
$length = str_replace(" ","",$exif["SubIFD"]["FocalLength"]);
$shutter = str_replace(" ","",str_replace("ec","",$exif["SubIFD"]["ShutterSpeedValue"]));
$aperture = $exif["SubIFD"]["ApertureValue"];
$iso = $exif["SubIFD"]["ISOSpeedRatings"];
list($width,$height) = getimagesize($photo);
if ($height >= $width) {
$photolist .= '<span data-title="'.$title.'" data-desc="'.$desc.'" data-camera="'.$camera.'" data-lens="'.$lens.'" data-length="'.$length.'" data-shutter="'.$shutter.'" data-aperture="'.$aperture.'" data-iso="'.$iso.'" style="background-image:url('.$photo.'); background-size:contain;" class="slide"></span>';
} else {
$photolist .= '<span data-title="'.$title.'" data-desc="'.$desc.'" data-camera="'.$camera.'" data-lens="'.$lens.'" data-length="'.$length.'" data-shutter="'.$shutter.'" data-aperture="'.$aperture.'" data-iso="'.$iso.'" style="background-image:url('.$photo.'); background-size:cover;" class="slide"></span>';
}
}
?>
幻灯片的 div 设置如下:
<div class="cycle-slideshow" data-cycle-slides="> span" data-cycle-timeout="10000" data-cycle-speed="1000" data-cycle-sync=false data-cycle-overlay-template="
<div class='photo_title'>{{title}}</div>
<div class='photo_desc'>{{desc}}</div>
<div class='exif'>{{camera}}, {{lens}} @ {{length}}, {{shutter}}, {{aperture}}, ISO {{iso}}
</div>
<img src='images/close_pane.png' class='fadein close_pane button toggleinfo' alt='Close Info Pane'>" data-cycle-prev="#prev" data-cycle-next="#next" id="slideshow">
<div class="cycle-overlay custom info"></div>
<?php echo $photolist; ?>
</div>
还有一个专辑列表,生成如下:
<div class="toggleblock pane" id="albums">
<?php
$directory = 'gallery/*';
$subfolders = glob($directory);
foreach($subfolders as $subfolder) {
$album = explode('_'. $subfolder);
$albumname = str_replace(' ','%20',$album[1]);
echo '<a href="#" class="fadein togglealbum" id="',$subfolder,'">',$albumname,'</a>';
}
?>
<img src="images/close_pane.png" class="togglelink fadein close_pane button" data-block="albums" alt="Close Album List">
</div>
当用户点击其中一张专辑时,会触发以下 jQuery:
$('.togglealbum').on('click',function() {
var slideshow = $('#slideshow');
slideshow.cycle('destroy');
slideshow.html("HTML GOES HERE");
slideshow.cycle();
$.cookie("currentalbum",(this).id,{expires:7});
});
slideshow.html()
对于如何将新幻灯片的 HTML 获取到该方法中,我已经摸索了一两天了。现在发生的情况是,由于设置了 cookie,当您单击相册然后刷新页面时,会加载新相册。我想过也许让这种方法重新加载页面本身(我还不知道这是否可能),但这似乎真的很不雅。
有什么方法可以让幻灯片生成的代码基本上重新运行吗?
我还考虑过提前生成所有专辑的所有幻灯片,并将它们填充到带有变量名的变量中(我知道大多数人讨厌它们,但我喜欢 PHP 中变量变量的概念),但我仍然可以' t 实现从 PHP 代码到 jQuery 的飞跃。
有人可以帮我吗?