菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
77
0

基于jquery编写的放大镜插件

原创
05/13 14:22
阅读数 95893
/**
  ***********************************************
  **此插件使用须知---------------       **
  **滤镜(inner)与其活动区(active)之比要等于 **
  **放大区(movequ)与其内部图片之比。如比值不相 **
  **等,请改变图片大小.----bqcSkwt--------------------**
  **参数介绍                  **
  **active:滤镜活动区             **
  **inner:滤镜                 **
  **movequ:放大区域              **
  **需在Html头部引入本js脚本及jquery-1.8.3脚本 **
  **如有疑问,请联系QQ:64047399,为你解答   **
  *********************************编程客栈**************
 
**/
 
 
$.fn.extend({
  yangbo:function(active,inner,movequ){
    $(active).hover(function(){
      $(inner).show();
      $(movequ).show();
      var proportionOne=$(active).width()/bqcSkwt$(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().left*proportionLeft).scrollTop($(inner).position()
        .top*proportionTop);
 
        //以下为小滤镜拖拽
        $(inner).offset({
            left:even编程客栈t.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('图片宽高不正确:请调整图片宽高-->滤镜与其父亲之比应该等于右侧盒子与右侧图片之比')
      .css({
        background:'yellow',
        color:'red',
      });
    }
  },function(){
      $(inner).hide();
      $(movequ).hide();
    })
 
 
  }
 
})

以上就是本文的全部内容,希望对大家的学习有所帮助。

本文标题: 基于jquery编写的放大镜插件
本文地址: http://www.cppcns.com/wangluo/javascript/145564.html

发表评论

0/200
77 点赞
0 评论
收藏
为你推荐 换一批