切换JQuery插件

时间:2014-12-27 09:12:38

标签: javascript jquery html plugins

我有一个图像,我使用imageLens插件调用缩放效果。它工作,但我想切换插件,每次单击文本。我尝试在许多地方使用.toggle(),但它要么切换图像或点击文本,要么切换插件。我怎样才能做到这一点。

HTML:

<li ><a href="#" id="zoom">Pan/Zoom</a></li>
<img src="bg.jpg" id="img1" width="100%" height="100%" style="position: absolute, z-index: -1"/ >

脚本:

$('#zoom').click(function() {
            $('#img1').imageLens({ lensSize: 150 });
    });

1 个答案:

答案 0 :(得分:1)

你可以通过小调整来做到这一点:

<强>脚本:

    var flag=0;
  $(document).ready(function(){
     $('#img1').imageLens();
     $('#zoom').click(function() {
         flag=flag+1;
         if(flag%2 == 0){
          $('#img1').off();
        }else{
         $('#img1').imageLens({ lensSize: 150 });

          }
            });

     });

<强> HTML:

<li ><a href="#" id="zoom">Pan/Zoom</a></li>
<img src="bg.jpg" id="img1" width="100%" height="100%" style="position: absolute, z-index: -1" />