[英]Custom Caption Display, jQuery, javascript
I was playing around with an image gallery function I constructed, attempting to produce a caption below the full image using the thumbnails' image attributes. 我在玩我构造的图像库功能,尝试使用缩略图的图像属性在完整图像下方生成标题 。 alt and title specifically. alt和标题 。 The thumbnail-gallery side has no issues. 缩略图库侧没有问题。 The caption on the other hand is returning undefined , and is appearing below the first thumbnail, instead of below the full image. 另一方面,标题返回undefined ,并显示在第一个缩略图下方,而不是完整图像下方。
$('.gallery li img').hover(function(){
var $viewer = $(this).parents('.viewer');
$('.full-img',$viewer).attr('src',$(this).attr('src').replace('thumb/', ''));
$('.full-img',$viewer).attr('alt',$(this).attr('alt').replace('thumb/', ''));
var caption_alt = $('.full-img',$viewer).attr('alt');
var caption_title = $('.full-img',$viewer).attr('title');
if (caption_alt !== "" && caption_title !== ""){('.full-img', $viewer).after('<p class="captiontitle">' + caption_title + '</p>' + '<p class="captionalt">' + caption_alt + '</p>')}
});
try this 尝试这个
$('.gallery li img').hover(function(){
var $viewer = $(this).parents('.viewer');
$('.full-img',$viewer).attr('src',$(this).attr('src').replace('thumb/', ''));
$('.full-img',$viewer).attr('alt',$(this).attr('alt').replace('thumb/', ''));//missed . here
var caption_alt = $('.full-img',$viewer).attr('alt');//missed . here
var caption_title = $('.full-img',$viewer).attr('title');//missed . here
if (caption_alt !== "" && caption_title !== ""){('.full-img', $viewer).after('<p class="captiontitle">' + caption_title + '</p>' + '<p class="captionalt">' + caption_alt + '</p>')}
}); //missed a . and an ending double quote "
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.