簡體   English   中英

如何在鼠標懸停時顯示標題並將圖像隱藏在同一div,jquery和Bootstrap中

[英]how to show the title on mouse over and hide the image in the same div, jquery and Bootstrap

主要是我在網站上使用Bootstrap
我想將鼠標懸停在代表文章的圖像上,並顯示文章標題,然后圖像將隱藏。
鼠標離開時將隱藏標題並顯示圖像
有人可以幫忙嗎?

提前致謝!!

HTML

<div class="carousel" data-ride="carousel" >
<div class="carousel-inner" role="listbox">
    <div class="item active" >
        <?php displayData('sumbola','1','image'); ?>    
        <div class="carousel-caption hide">
            <h3 ><?php  displayData('sumbola','1','title'); ?></h3>
            <a href="labels.php?id=1">Διαβάστε<br>περισσότερα.</a>
        </div>
    </div>
</div>

jQuery查詢

//顯示文章標題

$(".item").on('mouseenter',function(){ // if mouse-over the icon then the title will show up 
$(".carousel-caption").removeClass("hide");
$(".imglabel").addClass("hide"); // and the image will hide
});

$(".item").on('mouseleave',function(){
$(".carousel-caption").addClass("hide"); //if the mouse leave, then the image will appear again
$(".imglabel").removeClass("hide"); //and the title will leave
});

使用鼠標懸停並添加屬性“ display:none”,它比您使用的方法容易得多:

$(".item").hover( function(){
 $(".carousel-caption").attr("display","block");
 $(".imglabel").attr("display","none");
},function(){
 $(".carousel-caption").attr("display","none");
 $(".imglabel").attr("display","block");
})

另一件事是,我個人認為最好在此使用ID。 因此,您可以使用(“ #ItemID”)代替(“ .item”)為您擁有的每個不同項目設置特定操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM