Animation.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * 空白随鼠标移动
  3. * @authors Your Name (you@example.org)
  4. * @date 2014-08-31 09:38:16
  5. * @version $Id$
  6. */
  7. var caseFun = Object();
  8. caseFun.txtPos = function()
  9. {
  10. //字符串上下居中
  11. $(".j-list-case li").each(function(){
  12. var objTxt = $(".j-list-case li").find(".txt").children("span");
  13. var height = objTxt.height();
  14. objTxt.css("margin-top",($(".j-list-case li").height() - height) / 2 + "px");
  15. });
  16. }
  17. caseFun.moveFun = function() { //文字框移动
  18. var moveTime = 200;
  19. var moveIn = function(obj, direction) {
  20. switch (direction) {
  21. case 0:
  22. obj.css({
  23. "top": "-242px",
  24. "left": "0"
  25. });
  26. break;
  27. case 1:
  28. obj.css({
  29. "top": "0",
  30. "left": "242px"
  31. });
  32. break;
  33. case 2:
  34. obj.css({
  35. "top": "242px",
  36. "left": "0"
  37. });
  38. break;
  39. case 3:
  40. obj.css({
  41. "top": "0",
  42. "left": "-242px"
  43. });
  44. break;
  45. }
  46. obj.stop().animate({
  47. "top": "0",
  48. "left": "0"
  49. }, moveTime, 'easeOutSine');
  50. }
  51. var moveOut = function(obj, direction) {
  52. switch (direction) {
  53. case 0:
  54. obj.stop().animate({
  55. "top": "-242px",
  56. "left": "0"
  57. }, moveTime, 'easeOutSine');
  58. break;
  59. case 1:
  60. obj.stop().animate({
  61. "top": "0",
  62. "left": "242px"
  63. }, moveTime, 'easeOutSine');
  64. break;
  65. case 2:
  66. obj.stop().animate({
  67. "top": "242px",
  68. "left": "0"
  69. }, moveTime, 'easeOutSine');
  70. break;
  71. case 3:
  72. obj.stop().animate({
  73. "top": "0",
  74. "left": "-242px"
  75. }, moveTime, 'easeOutSine');
  76. break;
  77. }
  78. }
  79. $(".j-list-case li").bind("mouseenter mouseleave", function(e) {
  80. var obj = $(this)
  81. var objTxt = obj.find(".txt");
  82. var w = obj.width();
  83. var h = obj.height();
  84. var x = (e.pageX - this.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1);
  85. var y = (e.pageY - this.offsetTop - (h / 2)) * (h > w ? (w / h) : 1);
  86. var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
  87. var eventType = e.type;
  88. if (e.type == 'mouseenter') {
  89. moveIn(objTxt, direction);
  90. $(this).children("img").animate({width:"120%",height:"120%",marginTop:"-10%",marginLeft:"-10%"},100);
  91. } else {
  92. moveOut(objTxt, direction);
  93. $(this).children("img").animate({width:"100%",height:"100%",marginTop:"0",marginLeft:"0"},100);
  94. }
  95. });
  96. $('.j-list-case .txt').click(function() { //兼容移动端回退状态
  97. var obj = $(this);
  98. moveOut(obj, 0);
  99. })
  100. }
  101. caseFun.txtPos();
  102. caseFun.moveFun();