jquery 图片自由拼凑,鼠标移上图片晃动效果代码

迈不过友情╰ 2022-08-23 11:53 247阅读 0赞
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>鼠标移上图片晃动效果</title>
  6. <script type="text/javascript" src="script/jquery.1.6.3.js"></script>
  7. <script type="text/javascript">
  8. $(window).load(function(){
  9. var thumbnail = {imgIncrease : 10,effectDuration : 200};
  10. $(".free_bk li").each(function(index,item){
  11. var current_img = $(item).find("img");
  12. if (current_img.length > 0) {
  13. var currentWidth = 0,
  14. currentHeight = 0;
  15. currentWidth = current_img.width();
  16. currentHeight = current_img.height();
  17. $(item).width(currentWidth).height(currentHeight);
  18. $(item).hover(function() {
  19. var currentImg = $(item).find("img");
  20. thumbnail.imgIncreaseWidth = Math.floor(parseInt(currentWidth) * 0.02);
  21. thumbnail.imgIncreaseHeight = Math.floor(parseInt(currentHeight) * 0.02);
  22. currentImg.stop().animate({
  23. width: parseInt(currentWidth) + thumbnail.imgIncrease,
  24. left: thumbnail.imgIncreaseWidth / 2 * ( - 1),
  25. top: thumbnail.imgIncreaseHeight / 2 * ( - 1)
  26. },
  27. {
  28. "duration": thumbnail.effectDuration,
  29. "queue": false
  30. });
  31. $(item).find(".caption:not(:animated)").slideDown(thumbnail.effectDuration)
  32. },
  33. function() {
  34. var currentImg = $(item).find("img");
  35. currentImg.animate({
  36. width: currentWidth,
  37. left: 0,
  38. top: 0
  39. },
  40. thumbnail.effectDuration);
  41. $(item).find(".caption").slideUp(thumbnail.effectDuration)
  42. })
  43. }
  44. });
  45. });
  46. </script>
  47. <style type="text/css">
  48. .free_bk{ width:970px; height:440px; position:relative; overflow:hidden;}
  49. .free_bk li{margin:0 1px 1px 0; display:block; font-size:0; position:relative;overflow:hidden; }
  50. .free_bk ul li a img{position:relative; border:0;}
  51. </style>
  52. </head>
  53. <body>
  54. <div class="free_bk">
  55. <ul>
  56. <li><a href="#" class="" title="1"><img alt="图片名称关键字" src="images/1.jpg" /></a></li>
  57. <li><a href="#" class="" title="2"><img alt="图片名称关键字" src="images/2.jpg" /></a></li>
  58. <li><a href="#" class="" title="3"><img alt="图片名称关键字" src="images/3.jpg" /></a></li>
  59. <li><a href="#" class="" title="4"><img alt="图片名称关键字" src="images/4.jpg" /></a></li>
  60. </ul>
  61. </div>
  62. </body>
  63. </html>

发表评论

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

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

相关阅读