我正在使用 jQuery 从 XML 文件中获取结果并在 div 中显示每个条目。这是可行的,但现在我想这样做,以便如果我单击 div,它会在灯箱中显示来自 xml 的更多数据。
我在这里创建了一个 jsfiddle ,但它不起作用:
这是我的html:
<section id="page3">
<section class="portfolio row">
<! Hier komen cases uit xml !>
<div id="clearfix"></div>
</section>
<section class="portfolio_detail">
<span class="prev"><</span>
<section class="ajax_image"></section>
<span class="next">></span>
<span class="close">X</span>
<section class="watermark">
<p>Thomas More © Insilencio<br>
Corporate identity maximum two lines</p>
</section>
</section>
</section>
这是我的 jQuery:
$.ajax({
type: 'GET',
url: "hellojames.commefort.com/onepager/data.xml",
dataType: "xml",
success: function (data) {
//console.log(data);
$(data).find("case").each(function () {
var dezeCase = $(this);
var id = dezeCase.find("id").text();
var titel = dezeCase.find("titel").text();
var thumb = dezeCase.find("thumb").text();
var full = dezeCase.find("full");
var images = full.find('img');
var imagesArray = images;
var html = '<div class="portfolio_item col" id="' + titel + '"><img src="' + thumb + '" alt="' + titel + '"><p class="caption">' + titel + '</p></div>';
$('.portfolio').prepend(html);
mouseHover();
caseClick(imagesArray);
});
}
});
function mouseHover() {
$('.portfolio_item').mouseover(function () {
$(this).children('img').addClass("hover");
$(this).children('.caption').show();
//console.log('hover');
}).mouseout(function () {
$(this).children('img').removeClass("hover");
//console.log('stophover');
$('.caption').hide();
});
};
function caseClick(afbeeldingen) {
/* Detailpagina */
$('.portfolio_item').on('click', function () {
var lightbox = $('.portfolio_detail');
$(".ajax_image").empty();
lightbox.show().children().hide();
lightbox.animate({
width: '100%',
height: "100%"
}, 'fast');
lightbox.children().fadeIn('slow');
var inhoud = "<img src='" + afbeeldingen + "'>";
$(".ajax_image").append(inhoud);
});
};