VACross.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. VACross = function(w, show) {
  2. this.window = w ? w : window;
  3. this.isShow = !!show;
  4. this.move = jQuery.proxy(this.move, this);
  5. this.show = jQuery.proxy(this.show, this);
  6. this.hide = jQuery.proxy(this.hide, this);
  7. this.active = jQuery.proxy(this.active, this);
  8. }
  9. VACross.prototype = {
  10. active: function() {
  11. this.x = jQuery("<div va='cross' id='x' style='display:none;width:100%;height:5px;background:#ff0000 !important;position:absolute;z-index:1000;top:-10;left:-10;'></div>");
  12. this.y = jQuery("<div va='cross' id='y' style='display:none;width:5px;height:100%;background:#ff0000 !important;position:absolute;z-index:1000;top:-10;left:-10;'></div>");
  13. jQuery(this.window.document.body).append(this.x);
  14. jQuery(this.window.document.body).append(this.y);
  15. if (this.isShow) {
  16. this.show();
  17. }
  18. else {
  19. this.hide();
  20. }
  21. },
  22. move: function(event) {
  23. d = event.pageX,
  24. c = event.pageY;
  25. var st = this.window.document.documentElement.scrollTop ? this.window.document.documentElement.scrollTop : this.window.document.body.scrollTop;
  26. var sl = this.window.document.documentElement.scrollLeft ? this.window.document.documentElement.scrollLeft : this.window.document.body.scrollLeft;
  27. this.x.offset({ top: c - 6, left: sl });
  28. this.y.offset({ top: st, left: d - 6 });
  29. },
  30. show: function() {
  31. this.x.show();
  32. this.y.show();
  33. jQuery(this.window.document).bind("mousemove", this.move);
  34. jQuery(this.window).bind("scroll", this.move);
  35. this.isShow = true;
  36. },
  37. hide: function() {
  38. this.x.hide();
  39. this.y.hide();
  40. jQuery(this.window.document).unbind("mousemove", this.move);
  41. jQuery(this.window).unbind("scroll", this.move);
  42. this.isShow = false;
  43. }
  44. }