为了账号安全,请及时绑定邮箱和手机立即绑定

设置 maxzoom 和 minzoom 属性

设置 maxzoom 和 minzoom 属性

慕后森 2022-01-13 11:04:30
我想设置 maxzoom 和 minzoom 属性 - 因为当我单击 zoomin 按钮时,文本变得越来越大,所以我想在我的 jquery 代码中设置 maxzoom 和 minzoom 属性。我的 html 代码和 jquery 代码如下。重置按钮效果很好,但是当我继续单击放大和缩小按钮时,文本变得越来越大,而在缩小属性中,文本变得越来越小......所以我想设置 maxzoom 和 minzoom 属性。<button class="zoomIn">Zoom In</button><button class="zoomOff">Reset</button><button class="zoomOut">Zoom Out</button>enter code here<script>  $('.open-book').css({    // 'position' : 'absolute',    'top' : '0px',    'left' : '0px',    'height' : $('.outboard').height(),    'width' : $('.outboard').width()  });  var currZoom = 1;  $(".zoomIn").click(function(){    currZoom+=0.1;    $('.open-book').css({      // 'position' : 'absolute',      // 'top' : '45px',      // 'left' : '20px',      // 'height' : $(window).height()-65,      // 'width' : $(window).width()-40,      'zoom' : currZoom    });  });  $(".zoomOff").click(function(){    currZoom=1;    $(".open-book").css({      // 'position' : 'absolute',      // 'top' : '45px',      // 'left' : '20px',      // 'height' : $(window).height()-65,      // 'width' : $(window).width()-40,      'zoom' : currZoom    });  });  $(".zoomOut").click(function(){    currZoom-=0.1;    $('.open-book').css({      // 'position' : 'absolute',      // 'top' : '45px',      // 'left' : '20px',      // 'height' : $(window).height()-65,      // 'width' : $(window).width()-40,      'zoom' : currZoom    });  });
查看完整描述

1 回答

?
饮歌长啸

TA贡献1951条经验 获得超3个赞

您必须定义minZoom和maxZoom值并与 进行比较currZoom。通过包装在if条件和更改元素中比较值CSS。


试试这个代码。


<button class="zoomIn">Zoom In</button>

<button class="zoomOff">Reset</button>

<button class="zoomOut">Zoom Out</button>enter code here


<script>

  $('.open-book').css({

    // 'position' : 'absolute',

    'top' : '0px',

    'left' : '0px',

    'height' : $('.outboard').height(),

    'width' : $('.outboard').width()

  });


  var currZoom = 1;

  var minZoom = 1;

  var maxZoom = 2;


  $(".zoomIn").click(function(){


    if(maxZoom >= currZoom){

      currZoom+=0.1;

      $('.open-book').css({

        // 'position' : 'absolute',

        // 'top' : '45px',

        // 'left' : '20px',

        // 'height' : $(window).height()-65,

        // 'width' : $(window).width()-40,

        'zoom' : currZoom

      });

    }


  });

  $(".zoomOff").click(function(){


    currZoom=1;


    $(".open-book").css({

      // 'position' : 'absolute',

      // 'top' : '45px',

      // 'left' : '20px',

      // 'height' : $(window).height()-65,

      // 'width' : $(window).width()-40,

      'zoom' : currZoom

    });

  });

  $(".zoomOut").click(function(){


    if(minZoom <= currZoom){

      currZoom-=0.1;

      $('.open-book').css({

        // 'position' : 'absolute',

        // 'top' : '45px',

        // 'left' : '20px',

        // 'height' : $(window).height()-65,

        // 'width' : $(window).width()-40,

        'zoom' : currZoom

      });

    }


  });

</script>



查看完整回答
反对 回复 2022-01-13
  • 1 回答
  • 0 关注
  • 577 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号