VAZoom.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. VAZoom = function(w, zoom) {
  2. this.window = w ? w : window;
  3. this.zoom = zoom ? zoom : 1.0;
  4. this.zoomMax = 4.0;
  5. this.zoomMin = 0.5;
  6. this.zoomIn = jQuery.proxy(this.zoomIn, this);
  7. this.zoomOut = jQuery.proxy(this.zoomOut, this);
  8. this.doZoom = jQuery.proxy(this.doZoom, this);
  9. this.ratio = jQuery.proxy(this.ratio, this);
  10. this.active = jQuery.proxy(this.active, this);
  11. }
  12. VAZoom.prototype = {
  13. active: function () {
  14. this.doZoom();
  15. },
  16. zoomIn: function() {
  17. this.zoom -= 0.1;
  18. this.doZoom(this.zoom);
  19. return this.zoom - this.zoomMin > 0.05;
  20. },
  21. zoomOut: function() {
  22. this.zoom += 0.1;
  23. this.doZoom(this.zoom);
  24. return this.zoomMax - this.zoom > 0.05;
  25. },
  26. ratio: function(zoom) {
  27. if (zoom) {
  28. this.zoom = parseFloat(zoom);
  29. this.doZoom(this.zoom);
  30. }
  31. else {
  32. return this.zoom;
  33. }
  34. },
  35. doZoom: function() {
  36. var b = jQuery(this.window.document.body);
  37. var w = b.outerWidth();
  38. var h = b.outerHeight();
  39. if (jQuery.browser.mozilla) {
  40. b.css({ 'margin-top': h * (this.zoom - 1) / 2, '-moz-transform': 'scale(' + this.zoom + ')' })
  41. }
  42. else {
  43. b.css('zoom', this.zoom);
  44. document.scrollLeft = w * (this.zoom - 1) / 2;
  45. try {
  46. this.window.document.body.scrollLeft = w.width * (this.zoom - 1) / 2
  47. }
  48. catch (d) { }
  49. }
  50. }
  51. }