jquery鼠标移上图片变暗

àì夳堔傛蜴生んèń 2022-09-26 11:54 258阅读 0赞
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>hover</title>
  6. <script src="jquery.min.js"></script>
  7. <style type="text/css">
  8. *{ margin:0; padding:0; list-style:none;}
  9. .box li{ width:300px; height:200px; position:relative; float:left;}
  10. .box li a img{width:300px; height:200px;}
  11. .mask{ position:absolute; left:0; top:0; width:300px; height:200px; background:#000; filter:alpha(opacity=60); opacity:0.6; }
  12. </style>
  13. <script type="text/javascript">
  14. $(document).ready(function(){
  15. /*$(".box li a").each(function(){
  16. $(this).hover(
  17. function(){
  18. var $items = $(".box li a");
  19. t = setInterval(function(){
  20. $items.find("div").addClass("mask");
  21. },300);
  22. },function(){
  23. clearInterval(t);
  24. $(this).find("div").removeClass("mask");
  25. })
  26. });*/
  27. $(".box li a").mask();
  28. })
  29. $.fn.mask = function(){
  30. var items = $(this);
  31. $.each(items, function(index, item){
  32. $(item).hover(function(){
  33. $(this).find("div").addClass("mask");
  34. }, function(){
  35. $(this).find("div").removeClass("mask");
  36. });
  37. });
  38. };
  39. </script>
  40. </head>
  41. <body>
  42. <div class="box">
  43. <ul>
  44. <li><a href="#" class="pic"><img src="pic4.jpg"/><div class=""></div></a></li>
  45. <li><a href="#" class="pic"><img src="pic4.jpg"/><div class=""></div></a></li>
  46. <li><a href="#" class="pic"><img src="pic4.jpg"/><div class=""></div></a></li>
  47. <li><a href="#" class="pic"><img src="pic4.jpg"/><div class=""></div></a></li>
  48. </ul>
  49. </div>
  50. </body>
  51. </html>

发表评论

表情:
评论列表 (有 0 条评论,258人围观)

还没有评论,来说两句吧...

相关阅读