jquery.jloupe.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. jQuery Loupe v1.1
  3. Copyright (C) 2008 Chris Iufer (chris@iufer.com)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>
  14. */
  15. $(function(){
  16. var loupe = {'width' : 200, 'height': 151};
  17. $('<div id="thejLoupe"/>').addClass('thejLoupe').css('position','absolute').css('width',loupe.width+'px').css('height',loupe.height+'px').css('backgroundColor','rgba(0,0,0,0.25)').hide().appendTo('body');
  18. $('<div id="zoomWrapper" />').css('width',loupe.width-10+'px').css('height',loupe.height-10+'px').css('overflow','hidden').css('marginTop','5px').css('marginLeft','5px').appendTo('#thejLoupe');
  19. $('.jLoupe').each(function(){
  20. var s = ($(this).attr('longdesc') != undefined) ? $(this).attr('longdesc') : $(this).attr('src');
  21. var i = $('<img />').bind('load',function(){
  22. $(this).data('size',{'width':this.width, 'height':this.height});
  23. }).attr('src', s).hide().appendTo('#zoomWrapper');
  24. $(this).data('zoom',i);
  25. })
  26. .bind('mousemove', function(e){
  27. var o = $(this).offset();
  28. var i = $(this).data('zoom');
  29. $('#thejLoupe').css('left',e.pageX+10).css('top',e.pageY+10);
  30. var zlo = ((e.pageX - o.left) / this.width) * $(i).data('size').width - 86;
  31. var zto = ((e.pageY - o.top) / this.height) * $(i).data('size').height - 62;
  32. $(i).css('marginLeft', zlo * -1 + 'px').css('marginTop', zto * -1 + 'px').show();
  33. })
  34. .bind('mouseout', function(e){
  35. $(this).data('zoom').hide();
  36. $('#thejLoupe').hide();
  37. })
  38. .bind('mouseover', function(e){
  39. $(this).data('zoom').show();
  40. $('#thejLoupe').show();
  41. });
  42. });