在我的项目中,我有这个代码,我需要在使用Fancybox
的图像弹出框上添加一个链接
<?php if ($this->dados_globais['popup'] && $this->router->fetch_class() == "home") {
foreach ($this->dados_globais['popup'] as $popup) {
if ($popup->imagem) {
$img = base_url('./admin/assets/upload/popups/' . $popup->imagem);
echo '<a class="popup" data-fancybox="popups" href="' . $img . '" title="' . $popup->nome . '" data-caption="' . $popup->nome . '"></a>';
} else {
$link = $popup->link;
echo '<a class="popup" data-fancybox="popups" href="' . $link . '"></a>';
}
}
} ?>
请告诉我,以便我可以在图像上插入链接。
你只需要弄清楚如何创建链接到缩略图图像,然后放置在<a>
元素,像这样:
echo '<a class="popup" data-fancybox="popups" href="' . $img . '" title="' . $popup->nome . '" data-caption="' . $popup->nome . '"><img src="' . $img . '" /></a>';
我这样做了,它成功了
<?php if ($this->dados_globais['popup'] && $this->router->fetch_class() == "home") {
foreach ($this->dados_globais['popup'] as $popup) {
if ($popup->imagem) { ?>
<script>
$(document).ready(function() {
var url = '<?php echo $popup->link_imagem ?>';
url = url.replace(/^https?:///i, '');
$('.fancybox-content').attr('data-url', url);
$('.fancybox-content').css('cursor', 'pointer');
$(".fancybox-content").click(function() {
var url = $(this).attr('data-url');
window.open('http://' + url, '_blank');
return false;
});
});
</script>
<?php $img = base_url('./admin/assets/upload/popups/' . $popup->imagem);
echo '<a class="popup" data-fancybox="popups" href="' . $img . '" title="' . $popup->nome . '" data-caption="' . $popup->nome . '"></a>';
} else {
$link = $popup->link;
echo '<a class="popup" data-fancybox="popups" href="' . $link . '"></a>';
}
}
} ?>
<script>
$(document).ready(function() {
$(".popup").fancybox({
'overlayShow': true
});
if ($(".popup").length) {
$(".popup:first").click();
}
});
</script>