本文實(shí)例為大家分享了自己動(dòng)手實(shí)現(xiàn)的jquery放大鏡插件,供大家參考,具體內(nèi)容如下
/** *********************************************** **此插件使用須知--------------- ** **濾鏡(inner)與其活動(dòng)區(qū)(active)之比要等于 ** **放大區(qū)(movequ)與其內(nèi)部圖片之比。如比值不相 ** **等,請(qǐng)改變圖片大小.------------------------** **參數(shù)介紹 ** **active:濾鏡活動(dòng)區(qū) ** **inner:濾鏡 ** **movequ:放大區(qū)域 ** **需在Html頭部引入本js腳本及jquery-1.8.3腳本 ** **如有疑問(wèn),請(qǐng)聯(lián)系QQ:64047399,為你解答 ** *********************************************** **/ $.fn.extend({ yangbo:function(active,inner,movequ){ $(active).hover(function(){ $(inner).show(); $(movequ).show(); var proportionOne=$(active).width()/$(inner).width(); var proportionTwo=$(movequ).find('img').width()/$(movequ).width(); // console.log($(movequ).find('img').width()); if(proportionOne==proportionTwo){ $(this).mousemove(function(event){ //以下為右側(cè)放大 var proportionLeft=$(active).width()/$(inner).width(); var proportionTop=$(active).height()/$(inner).height(); $(movequ).scrollLeft($(inner).position().left*proportionLeft).scrollTop($(inner).position() .top*proportionTop); //以下為小濾鏡拖拽 $(inner).offset({ left:event.pageX-40, top:event.pageY-40 }); //以下為判斷臨界值 if($(inner).position().left<=0){ $(inner).css({ left:0 }) } if($(inner).position().top<=0){ $(inner).css({ top:0 }) } if($(inner).position().left>=$(this).width()-$(inner).width()){ $(inner).css({ left:$(this).width()-$(inner).width() }) } if($(inner).position().top>=$(this).height()-$(inner).height()){ $(inner).css({ top:$(this).height()-$(inner).height() }) } }) }else{ $(active).text('圖片寬高不正確:請(qǐng)調(diào)整圖片寬高-->濾鏡與其父親之比應(yīng)該等于右側(cè)盒子與右側(cè)圖片之比') .css({ background:'yellow', color:'red', }); } },function(){ $(inner).hide(); $(movequ).hide(); }) } })
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。



















