鼠标经过隐藏图片显示文字

鼠标经过隐藏图片显示文字

鼠标经过隐藏图片显示文字

 

JavaScript Code
  1. <script>  
  2.   
  3. $(document).ready(function() {  
  4.     //if mouse over and mouse out  
  5.     $('.eff').hover(  
  6.     function () {  
  7.   
  8.         value = $(this).find('img').outerHeight() * -1;  
  9.   
  10.         //for left/right if you have different width and height,   
  11.         //commented out because we are using up/down in this example  
  12.         //value = $(this).find('img').outerWidth() * -1);   
  13.           
  14.         //animate the image  
  15.         // you can change the sliding direction by changing bottom to left, right or top  
  16.         // if you changed this, you will have to change the position of the hover out as well  
  17.         $(this).find('img').stop().animate({bottom: value} ,{duration:500, easing: 'easeOutBounce'});     
  18.           
  19.     },  
  20.     function () {  
  21.           
  22.         //reset the image  
  23.         // the position property (bottom), it must be same with the on in the mouseover  
  24.         $(this).find('img').stop().animate({bottom:0} ,{duration:500, easing: 'easeOutBounce'});      
  25.       
  26.     });  
  27.       
  28.     //if user clicked on the thumbnail  
  29.     $('.eff').click(function () {     
  30.         //grab and execute the first link in the thumbnail  
  31.         window.location = $(this).find('a:first').attr('href');  
  32.     });  
  33.       
  34. });  
  35.   
  36. </script>  

 

XML/HTML Code
  1. <div class="eff">  
  2.     <img src="1.gif" alt="Test 1" title="" width="126" height="126" />  
  3.     <div class="caption"><a href="http://www.freejs.net" class="header">www.freejs.net</a></div>  
  4. </div>  
  5.   
  6. <div class="eff">  
  7.     <img src="2.gif" alt="Test 1" title="" width="126" height="126" />  
  8.     <div class="caption"><a href="http://www.freejs.net" class="header">Umbrella</a><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p></div>  
  9. </div>  
  10.   
  11. <div class="eff">  
  12.     <img src="3.gif" alt="Test 1" title="" width="126" height="126" />  
  13.     <div class="caption"><a href="http://www.freejs.net" class="header">Maximum</a><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p></div>  
  14. </div>  
  15.   
  16. <div class="clear"></div>  

 


原文地址: http://www.freejs.net/article_jquerywenzi_107.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以在HTML中使用鼠标悬停事件(onmouseover)和JavaScript来实现鼠标经过图片显示文字的效果。具体实现步骤如下: 1. 在HTML中插入图片和要显示文字,可以使用HTML的<img>和<div>标签,给它们分别设置id和class属性。 2. 使用JavaScript编写函数,通过getElementById获取图片文字的元素,然后利用style属性修改文字的display属性,使其在鼠标悬停时显示出来,离开时隐藏起来。 3. 在图片元素中绑定onmouseover事件,使其在鼠标悬停时触发JavaScript函数,显示对应的文字。 下面是一个示例代码: HTML部分: ``` <img id="myImg" src="myImage.jpg"> <div id="myText" class="hide">这是图片的说明文字</div> ``` CSS部分: ``` .hide { display: none; } ``` JavaScript部分: ``` var img = document.getElementById("myImg"); var text = document.getElementById("myText"); img.onmouseover = function() { text.style.display = "block"; } img.onmouseout = function() { text.style.display = "none"; } ``` 在这个示例中,我们首先定义了一个id为"myImg"的图片元素和一个class为"hide"的文字元素,使用CSS将文字元素的display属性设置为none,使其默认情况下不显示。 然后在JavaScript中获取图片文字元素,定义onmouseover和onmouseout事件,当鼠标悬停在图片上时,将文字元素的display属性设置为block,使其显示出来;当鼠标离开图片时,将display属性设置为none,使其隐藏起来。 这样就可以实现鼠标经过图片显示文字的效果了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值