dtn55928 2014-11-28 20:53
浏览 41
已采纳

Jquery将显示页面上的所有灯箱

I've made a simple Lightbox that will pop up and the image will be shown , but when it comes to PHP things get wired.It opens all my div's that have the class lightbox in it.

Javascript:

$('.lightbox').click(function(){
$('.spate').animate({'opacity':'.50'}, 1000 , 'linear');
$('.box').animate({'opacity':'1.00'}, 1000 , 'linear');
$('.spate, .box').css('display','block');
});
$('.inchide').click(function(){
$('.spate, .box').animate({'opacity':'.0'}, 500 , 'linear', function(){
$('.spate, .box').css('display','none');
});  
});
$('.spate').click(function(){
$('.spate, .box').animate({'opacity':'.0'}, 500 , 'linear', function(){
$('.spate, .box').css('display','none');
});
});

PHP/HTML:

while($row=mysql_fetch_array($query){
$post_image= $row['post_image'];
<?php if(!$post_image=="") echo '
<a class="lightbox" href="#"><img src="img/'.$post_image.'"></a>
<div class="spate"></div>
<div class="box"><div class="inchide">X</div> <img src="img/'.$post_image.'"></div>
';
}

The problem is when i have more than 1 image on the page,if one of the images is clicked a lightbox will appear for all images in particular.I can't get it to open the lightbox just for the clicked image.

  • 写回答

2条回答 默认 最新

  • douhuang2673 2014-11-28 21:29
    关注
    while($row=mysql_fetch_array($query){
    $post_image= $row['post_image'];
    <?php if(!$post_image=="") echo '
    <div> <!--add all of that in div for each one-->
    <a class="lightbox" href="#"><img src="img/'.$post_image.'"></a>
    <div class="spate"></div>
    <div class="box"><div class="inchide">X</div> <img src="img/'.$post_image.'"></div>
    <div>
    ';
    }
    

    and use it like that

    $(document).ready(function(){
        $('.lightbox').click(function(){
        $(this).parent().find('.spate').animate({'opacity':'.50'}, 1000 , 'linear');
        $(this).parent().find('.box').animate({'opacity':'1.00'}, 1000 , 'linear');
        $(this).parent().find('.spate, .box').css('display','block');
        });
        $('.inchide').click(function(){
        $(this).parent().parent().find('.spate, .box').animate({'opacity':'.0'}, 500 , 'linear', function(){
        $(this).parent().parent().find('.spate, .box').css('display','none');
        });  
        });
        $('.spate').click(function(){
        $(this).parent().find('.spate, .box').animate({'opacity':'.0'}, 500 , 'linear', function(){
        $(this).parent().find('.spate, .box').css('display','none');
        });
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据