[英]Get content in same div jQuery
I've got a gallery on my website with each of them a unique ID. 我的网站上有一个画廊,每个画廊都有一个唯一的ID。 I'm trying to get this idea to work: Click on the first image = the content of first image.
我正在尝试使这个想法起作用:单击第一个图像=第一个图像的内容。 Click on the second image = the content of second image.. etc etc.
单击第二个图像=第二个图像的内容。等等,等等。
Currenlty i've set each image with a unique id as seen below: Currenlty我为每个图像设置了唯一的ID,如下所示:
echo "<img src='http://bsc.ua.edu/wp-content/uploads/2012/01/white-placeholder-100x100.jpg' data-original='$thumbnail[0]' width='$thumbnail[1]' height='$thumbnail[2]' class='lazygallery' id='$thumb_id'/>";
And with jQuery i can get all content in the screen, one for one. 借助jQuery,我可以将所有内容一一呈现在屏幕上。 So if I click img1 I get content 1.
因此,如果单击img1,我将获得内容1。
Got 2 loops, one for the thumbnails and one for the content: Thumbnail: 有2个循环,一个用于缩略图,一个用于内容:缩略图:
echo '<div class="gallery">';
while ($loop->have_posts()) : $loop->the_post($post->ID);
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'gallery-thumb', true, '');
$thumb_id = get_the_ID();
echo "<img src='http://bsc.ua.edu/wp-content/uploads/2012/01/white-placeholder-100x100.jpg' data-original='$thumbnail[0]' width='$thumbnail[1]' height='$thumbnail[2]' class='lazygallery' id='$thumb_id'/>";
endwhile;
echo '</div>';
The content loop is almost the same but then just other functions in side it (like the_content(), and a bunch of custom stuff). 内容循环几乎是相同的,但是它旁边只是其他函数(例如the_content()和一堆自定义内容)。
My script currently: 我的脚本当前:
<script>
$(document).ready(function () {
$('#<?php echo $thumb_id ?>').on('click', function () {
var idimg = $(this).attr('id');
alert('Id: ' + idimg);
$('.content_<?php echo $thumb_id ?>').toggle();
});
});
</script>
Full Question How can I get the script too work like this: Img1 gets clicked - show Content1 Img2 gets clicked - empty the div, then set Content2 Img3 gets clicked - empty the div, then set Content3 全问 我怎样才能拿到剧本太像这样的工作:IMG1被点击-显示内容1 IMG2被点击-空格,然后设置内容2 IMG3被点击-空格,然后设置Content3
We first need to make a 'display' div which is always visible. 我们首先需要创建一个始终可见的“ display” div。
Eg: 例如:
<div id="information"></div>
With CSS such as this: 使用这样的CSS:
#information {
position:fixed;
margin-top:50px;
margin-left:50px;
background-color:grey;
}
This div will display the information of the images we click on. 该div将显示我们单击的图像的信息。
Now to actually update this div with the information, we do the following: 现在要使用信息实际更新此div,我们执行以下操作:
$(document).ready(function () {
$('#<?php echo $thumb_id ?>').on('click', function () {
// get the correct content id
var idimg = $(this).attr('id');
var contentId = '.content_' + idimg;
// update information div
$('#information').html($(contentId).html());
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.