简体   繁体   English

悬停图像显示说明

[英]Hover image display description

I am trying to display description on hover image but when hover on image then all image display description. 我试图在悬停图像上显示描述,但是当悬停在图像上时,所有图像都会显示描述。 I have the following code.... 我有以下代码。

    <?php if ($product['thumb']) { ?>
    <div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></a></div>
    <?php } ?>

    <div style="display:none;" class="de"> Nunc ornare adipiscing orci eu consectetur. Ut justo libero, porttitor ac elementum luctus, bland..

    <img alt="Based on 2 reviews." src="catalog/view/theme/kid/stars1-4.png"/>
    </div>

    <script type="text/javascript">
    $this('.image').hover(function() {
    // mouseOver function
        $('.de').show();
    }, function() {
    // mouseOut function
    $('.de').hide();
    });
    </script>
<img src="/some/dir" title="Your description" alt="alternate text"/>

Is the correct way of adding an description. 是添加描述的正确方法。 Mind you, I'm not quite sure if that's what you're asking. 提醒您,我不确定这是否是您要的内容。

First of all, your div is display none, and your image is inside it. 首先,您的div不显示任何内容,并且图像位于其中。 So it won't be displayed. 因此它不会显示。

<div style="display:none;" class="de"> Nunc ornare adipiscing orci eu consectetur. Ut justo libero, porttitor ac elementum luctus, bland..
</div>
<img alt="Based on 2 reviews." src="catalog/view/theme/kid/stars1-4.png"/>

Do you have an example of how your html looks when there are more images? 当有更多图像时,您是否有HTML外观的示例? Here's the javascript I came up with, with your current html: 这是我想出的JavaScript,以及您当前使用的html:

<script type="text/javascript">
    $('img').hover(function() {
    // mouseOver function
        $(this).prev('.de').show();
    }, function() {
    // mouseOut function
        $(this).prev('.de').hide();
    });
</script>​

I've used the selector "img". 我已经使用了选择器“ img”。 But you might want to use a class, and maybe use a delegate (http://api.jquery.com/on/) 但是您可能想使用一个类,并且可能使用一个委托(http://api.jquery.com/on/)

Here's the fiddle: http://jsfiddle.net/BvLPY/6/ 这是小提琴: http : //jsfiddle.net/BvLPY/6/

happy coding! 祝您编码愉快!

updated 更新

use .next() in this script: 在此脚本中使用.next()

just find the next div to the hovering .image div 只需找到悬停.image div的下一个div

<script>
$(function(){
    $('.image').hover(function() {
    // mouseOver function
        $(this).next('.de').show();
    }, function() {
    // mouseOut function
        $(this).next('.de').hide();
    });​
});
</script>

find this in the fiddle: http://jsfiddle.net/SufeL/ 在小提琴中找到它: http : //jsfiddle.net/SufeL/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM