jquery.fly.min.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*! fly - v1.0.0 - 2014-12-22
  2. * https://github.com/amibug/fly
  3. * Copyright (c) 2014 wuyuedong; Licensed MIT */
  4. ! function(a) {
  5. a.fly = function(b, c) {
  6. var d = {
  7. version: "1.0.0",
  8. autoPlay: !0,
  9. vertex_Rtop: 20,
  10. speed: 1.2,
  11. start: {},
  12. end: {},
  13. onEnd: a.noop
  14. },
  15. e = this,
  16. f = a(b);
  17. e.init = function(a) {
  18. this.setOptions(a), !!this.settings.autoPlay && this.play()
  19. }, e.setOptions = function(b) {
  20. this.settings = a.extend(!0, {}, d, b);
  21. var c = this.settings,
  22. e = c.start,
  23. g = c.end;
  24. f.css({
  25. marginTop: "0px",
  26. marginLeft: "0px",
  27. position: "fixed"
  28. }).appendTo("body"), null != g.width && null != g.height && a.extend(!0, e, {
  29. width: 60,
  30. height: 60
  31. });
  32. var h = Math.min(e.top, g.top) - Math.abs(e.left - g.left) / 3;
  33. h < c.vertex_Rtop && (h = Math.min(c.vertex_Rtop, Math.min(e.top, g.top)));
  34. var i = Math.sqrt(Math.pow(e.top - g.top, 2) + Math.pow(e.left - g.left, 2)),
  35. j = Math.ceil(Math.min(Math.max(Math.log(i) / .05 - 75, 30), 100) / c.speed),
  36. k = e.top == h ? 0 : -Math.sqrt((g.top - h) / (e.top - h)),
  37. l = (k * e.left - g.left) / (k - 1),
  38. m = g.left == l ? 0 : (g.top - h) / Math.pow(g.left - l, 2);
  39. a.extend(!0, c, {
  40. count: -1,
  41. steps: j,
  42. vertex_left: l,
  43. vertex_top: h,
  44. curvature: m
  45. })
  46. }, e.play = function() {
  47. this.move()
  48. }, e.move = function() {
  49. var b = this.settings,
  50. c = b.start,
  51. d = b.count,
  52. e = b.steps,
  53. g = b.end,
  54. h = c.left + (g.left - c.left) * d / e,
  55. i = 0 == b.curvature ? c.top + (g.top - c.top) * d / e : b.curvature * Math.pow(h - b.vertex_left, 2) + b.vertex_top;
  56. if (null != g.width && null != g.height) {
  57. var j = e / 2,
  58. k = g.width - (g.width - c.width) * Math.cos(j > d ? 0 : (d - j) / (e - j) * Math.PI / 2),
  59. l = g.height - (g.height - c.height) * Math.cos(j > d ? 0 : (d - j) / (e - j) * Math.PI / 2);
  60. f.css({
  61. width: k + "px",
  62. height: l + "px",
  63. "font-size": Math.min(k, l) + "px"
  64. })
  65. }
  66. f.css({
  67. left: h + "px",
  68. top: i + "px"
  69. }), b.count++;
  70. var m = window.requestAnimationFrame(a.proxy(this.move, this));
  71. d == e && (window.cancelAnimationFrame(m), b.onEnd.apply(this))
  72. }, e.destory = function() {
  73. f.remove()
  74. }, e.init(c)
  75. }, a.fn.fly = function(b) {
  76. return this.each(function() {
  77. void 0 == a(this).data("fly") && a(this).data("fly", new a.fly(this, b))
  78. })
  79. }
  80. }(jQuery);