如何在悬停图像时显示删除选项?

时间:2016-08-03 06:42:12

标签: javascript jquery css codeigniter-3

我想在图像悬停时显示删除选项。我不知道该怎么做。所以请各位帮帮我?我的观点是这样的:

<?php include('inc/header.php');?>

    <div class="main">



        <?php
            foreach ($view as $row) {
                echo "<div class='grow'>";
                echo "<img src='".base_url()."images/".$row->image."' >";
                echo "</div>";  
                }//end for each

        ?>




    </div>
<?php include('inc/footer.php');?>

我的图片已经悬停,但不知道如何在图片中嵌入删除选项。

1 个答案:

答案 0 :(得分:0)

添加删除div -

<?php include('inc/header.php');?>

        <div class="main">



            <?php
                foreach ($view as $row) {
                    echo "<div class='grow'>";
                    echo "<div class='delete'><a href='#'>delete</a></div>";
                    echo "<img src='".base_url()."images/".$row->image."' >";
                    echo "</div>";  
                    }//end for each

            ?>




        </div>
    <?php include('inc/footer.php');?>

然后在脚本中编写一个代码来显示/隐藏删除div -

$('.grow').hover(function () {
                      $(this).find('.delete').show();
                   }, 

                   function () {
                      $(this).find('.delete').hide();
                   })