2013-01-01 79 views
2

我想显示悬停图像上的描述,但是当悬停在图像上,然后所有图像显示说明。 我有下面的代码....悬停图像显示说明

所有的
<?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> 
+0

使用工具ti p或设置alt标记 –

+0

检查答案中的小提琴。 – Jai

回答

0

首先,你的DIV是显示器没有,你的形象里面。所以它不会被显示。

<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"/> 

您是否有一个例子,说明您的html在有更多图像时的外观?这里的JavaScript我想出了,与您目前的HTML:

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

我已经使用选择器“IMG”。但是,你可能想使用一个类,也许使用委托(http://api.jquery.com/on/)

这里的小提琴: http://jsfiddle.net/BvLPY/6/

编码快乐!

1
<img src="/some/dir" title="Your description" alt="alternate text"/> 

是添加说明的正确方法。请注意,我不太确定这是否是您要求的。

+0

这可能在语义上是正确的,但对最终用户来说并不是非常有用。而且我甚至不确定它在语义上是否正确 - 我一直认为'alt'更喜欢'title',如果仅仅因为它是强制性的。 –

+1

我可以看到为什么你会使用alt标签进行描述,因为它可能是所有最被滥用的标签之一。但是,如果图像文件丢失/无法加载,alt标记的原始功能是提供替代文本。 –

+0

Alt不是标签。在进一步的研究中,我确实同意'alt'是用于替代文本而不是用于澄清文本。此外,'alt'对图像是强制性的,所以它应该在这个代码中。 –

0

更新

使用.next()在此脚本:

刚刚找到下一个div来的徘徊.image DIV

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

找到这个在小提琴:http://jsfiddle.net/SufeL/

+0

不要显示*全部*悬停文本! –

+0

oops没有很好地阅读这个问题。只是更新答案。 – Jai

+0

我认为需要检查最接近的图像 – Jai