zzsc.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. (function($){
  2. $.fn.jqueryzoom=function(options){
  3. var settings={
  4. xzoom:200,
  5. yzoom:200,
  6. offset:10,
  7. position:"right",
  8. lens:1,
  9. preload:1};
  10. if(options){
  11. $.extend(settings,options);}
  12. var noalt='';
  13. $(this).hover(function(){
  14. var imageLeft=$(this).offset().left;
  15. var imageTop=$(this).offset().top;
  16. var imageWidth=$(this).children('img').get(0).offsetWidth;
  17. var imageHeight=$(this).children('img').get(0).offsetHeight;
  18. noalt=$(this).children("img").attr("alt");
  19. var bigimage=$(this).children("img").attr("jqimg");
  20. $(this).children("img").attr("alt",'');
  21. if($("div.zoomdiv").get().length==0){
  22. $(this).after("<div class='zoomdiv'><img class='bigimg' src='"+bigimage+"'/></div>");
  23. $(this).append("<div class='jqZoomPup'>&nbsp;</div>");}
  24. if(settings.position=="right"){
  25. if(imageLeft+imageWidth+settings.offset+settings.xzoom>screen.width){
  26. leftpos=imageLeft-settings.offset-settings.xzoom;}else{
  27. leftpos=imageLeft+imageWidth+settings.offset;}}else{
  28. leftpos=imageLeft-settings.xzoom-settings.offset;
  29. if(leftpos<0){
  30. leftpos=imageLeft+imageWidth+settings.offset;}}
  31. $("div.zoomdiv").css({top:imageTop,left:leftpos});
  32. $("div.zoomdiv").width(settings.xzoom);
  33. $("div.zoomdiv").height(settings.yzoom);
  34. $("div.zoomdiv").show();
  35. if(!settings.lens){
  36. $(this).css('cursor','crosshair');}
  37. $(document.body).mousemove(function(e){
  38. mouse=new MouseEvent(e);
  39. var bigwidth=$(".bigimg").get(0).offsetWidth;
  40. var bigheight=$(".bigimg").get(0).offsetHeight;
  41. var scaley='x';
  42. var scalex='y';
  43. if(isNaN(scalex)|isNaN(scaley)){
  44. var scalex=(bigwidth/imageWidth);
  45. var scaley=(bigheight/imageHeight);
  46. $("div.jqZoomPup").width((settings.xzoom)/(scalex*1));
  47. $("div.jqZoomPup").height((settings.yzoom)/(scaley*1));
  48. if(settings.lens){
  49. $("div.jqZoomPup").css('visibility','visible');}}
  50. xpos=mouse.x-$("div.jqZoomPup").width()/2-imageLeft;
  51. ypos=mouse.y-$("div.jqZoomPup").height()/2-imageTop;
  52. if(settings.lens){
  53. xpos=(mouse.x-$("div.jqZoomPup").width()/2 < imageLeft ) ? 0 : (mouse.x + $("div.jqZoomPup").width()/2>imageWidth+imageLeft)?(imageWidth-$("div.jqZoomPup").width()-2):xpos;
  54. ypos=(mouse.y-$("div.jqZoomPup").height()/2 < imageTop ) ? 0 : (mouse.y + $("div.jqZoomPup").height()/2>imageHeight+imageTop)?(imageHeight-$("div.jqZoomPup").height()-2):ypos;}
  55. if(settings.lens){
  56. $("div.jqZoomPup").css({top:ypos,left:xpos});}
  57. scrolly=ypos;
  58. $("div.zoomdiv").get(0).scrollTop=scrolly*scaley;
  59. scrollx=xpos;
  60. $("div.zoomdiv").get(0).scrollLeft=(scrollx)*scalex;});},function(){
  61. $(this).children("img").attr("alt",noalt);
  62. $(document.body).unbind("mousemove");
  63. if(settings.lens){
  64. $("div.jqZoomPup").remove();}
  65. $("div.zoomdiv").remove();});
  66. count=0;
  67. if(settings.preload){
  68. $('body').append("<div style='display:none;' class='jqPreload"+count+"'>360buy</div>");
  69. $(this).each(function(){
  70. var imagetopreload=$(this).children("img").attr("jqimg");
  71. var content=jQuery('div.jqPreload'+count+'').html();
  72. jQuery('div.jqPreload'+count+'').html(content+'<img src=\"'+imagetopreload+'\">');});}}})(jQuery);
  73. function MouseEvent(e){
  74. this.x=e.pageX;
  75. this.y=e.pageY;}