本文实例为大家分享了自己动手实现的jquery放大镜插件,供大家参考,具体内容如下
**/
$.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){
//以下为右侧放大
var proportionLeft=$(active).width()/$(inner).width();
var proportionTop=$(active).height()/$(inner).height();
$(movequ).scrollLeft($(inner).position().leftproportionLeft).scrollTop($(inner).position()
.toPproportionTop);
//以下为小滤镜拖拽
$(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('<a href="https://www.jb51.cc/tag/tupian/" target="_blank" class="keywords">图片</a>宽高不正确:请调整<a href="https://www.jb51.cc/tag/tupian/" target="_blank" class="keywords">图片</a>宽高-->滤镜与其父亲之比应该等于右侧盒子与右侧<a href="https://www.jb51.cc/tag/tupian/" target="_blank" class="keywords">图片</a>之比')
.css({
background:'yellow',color:'red',});
}
},function(){
$(inner).hide();
$(movequ).hide();
})
}
})
以上就是本文的全部内容,希望对大家的学习有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。