/// <reference path="../jquery11.js" /> 前端 ( function ($) { java $.fn.extend({ jquery jqoom: function (potions) { web var settings = { 瀏覽器 width: 350, app height: 350, ide position: "right" } if (potions) { $.extend(settings, potions); } var ImgUrl = $( "img" , this ).attr( "src" ); var ImgMinWidth = $( "img" , this ).width(); var ImgMinHeigth = $( "img" , this ).height(); var ImgWidth = 0; var ImgHeight = 0; var de = true ; $( this ).hover( function (e) { }, function () { $( "#jqoomz" ).remove(); $(document).unbind( "mousemove" ); $( "#jqoomy" ).remove(); de = true ; }); $( "img" , this ).hover( function (e) { var pagex = e.x || e.pageX; var pagey = e.y || e.pageY; var pagex1 = 0; var pagey1 = 0; var leftcha = 0; var topcha = 0; _this = $( this ).parents( "div" ); if ($( "#jqoomz" ).length == 0) { _this.after( "<div id='jqoomz'></div>" ); var obj = new Image(); obj.src = ImgUrl; obj.onload = function () { if (de && obj.height > 0) { de = false ; ImgWidth = obj.width; ImgHeight = obj.height; finder.call(_this.find( "img" )[0]); } }; $( "#jqoomz" ).width(settings.width).height(settings.height).offset({ left: $(_this).outerWidth() + $(_this).offset().left, top: $(_this)[0].offsetTop }).append($( "<img></img>" ).attr( "src" , ImgUrl)); if (de && obj.height > 0) { de = false ; ImgWidth = obj.width; ImgHeight = obj.height; finder.call( this ); } } function mover(event) { var pagex2 = event.x || event.pageX; var pagey2 = event.y || event.pageY; if (parseInt(pagex2 + leftcha) <= parseInt($(_this).width() + $(_this).offset().left) && pagex2 >= leftcha + $(_this).offset().left) { $( this ).offset({left: pagex2 - leftcha}); } else { if (parseInt(pagex2 + leftcha) > parseInt($(_this).width() + $(_this).offset().left) && pagex2) $( this ).offset({left: $(_this).width() + $(_this).offset().left - leftcha * 2}); else $( this ).offset({left: $(_this).offset().left}); } if (parseInt(pagey2 + topcha) <= parseInt($(_this).height() + $(_this).offset().top) && pagey2 >= topcha + $(_this).offset().top) { $( this ).offset({top: (pagey2 - topcha)}); //document.getElementById("move").style.top = (pagey2 - (this.pagey - this.divtop)).toString() + "px"; } else { if (parseInt(pagey2 + topcha) > parseInt($(_this).height() + $(_this).offset().top)) $( this ).offset({top: ($(_this).height() + $(_this).offset().top - topcha * 2)}); //document.getElementById("move").style.top = (this.height - this.divHeight).toString() + "px"; else $( this ).offset({top: $(_this).offset().top}); //document.getElementById("move").style.top = "0px" } var bilx = ($( this ).offset().left - $(_this).offset().left) / (ImgMinWidth / ImgWidth); var bily = ($( this ).offset().top - $(_this).offset().top) / (ImgMinHeigth / ImgHeight); $( "#jqoomz img" ).css({ "margin-left" : -bilx, "margin-top" : -bily}); } function finder() { if (parseFloat($( this ).offset().top + $( this ).height() - (ImgMinHeigth / ImgHeight * ImgMinHeigth)) >= parseFloat(pagey - ImgMinHeigth / ImgHeight * ImgMinHeigth / 2) && parseFloat(pagey - ImgMinHeigth / ImgHeight * ImgMinHeigth / 2) >= parseFloat($( this ).offset().top)) { pagey1 = (pagey - ImgMinHeigth / ImgHeight * ImgMinHeigth / 2); } else { if ((pagey - ImgMinHeigth / ImgHeight * ImgMinHeigth / 2) < $( this ).offset().top) { pagey1 = $( this ).offset().top; } else { pagey1 = ($( this ).offset().top + $( this ).height() - (ImgMinHeigth / ImgHeight * ImgMinHeigth)); } } if (($( this ).offset().left + $( this ).width() - ImgMinWidth / ImgWidth * ImgMinWidth) >= (pagex - ImgMinWidth / ImgWidth * ImgMinWidth / 2) && (pagex - ImgMinWidth / ImgWidth * ImgMinWidth / 2) >= $( this ).offset().left) { pagex1 = (pagex - ImgMinWidth / ImgWidth * ImgMinWidth / 2); } else { if ((pagex - ImgMinWidth / ImgWidth * ImgMinWidth / 2) < $( this ).offset().left) { pagex1 = $( this ).offset().left; } else { pagex1 = ($( this ).offset().left + $( this ).width() - ImgMinWidth / ImgWidth * ImgMinWidth); } } leftcha = ImgMinWidth / ImgWidth * ImgMinWidth / 2; topcha = ImgMinHeigth / ImgHeight * ImgMinHeigth / 2; if ($( "#jqoomy" ).length == 0) { $( this ).after( "<div id='jqoomy'></div>" ) .siblings( "#jqoomy" ) .addClass( "jqoomy" ).show() .width((ImgMinWidth / ImgWidth * ImgMinWidth)) .height((ImgMinHeigth / ImgHeight * ImgMinHeigth)).offset({ top: pagey1, left: pagex1 }); } $(document).on( "mousemove" , $.proxy(mover, $( "#jqoomy" ))); } }, function () { }); } }); })(jQuery); |