0

当我将 zoomooz.js 放入带有 jqueryui 自动完成功能的网页时,它只在第一次工作,下拉菜单不再接受鼠标点击。为了工作,我将鼠标移动到目标上,然后单击键盘上的 Enter 键。

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/zoomooz/1.1.6/jquery.zoomooz.min.js"></script>
 
<script>
  $( function() {
var availableTags = [
  "ActionScript",
  "AppleScript",
  "Asp",
  "BASIC",
  "C",
  "C++",
  "Clojure",
  "COBOL",
  "ColdFusion",
  "Erlang",
  "Fortran",
  "Groovy",
  "Haskell",
  "Java",
  "JavaScript",
  "Lisp",
  "Perl",
  "PHP",
  "Python",
  "Ruby",
  "Scala",
  "Scheme"
];
$( "#tags" ).autocomplete({
  source: availableTags
});
  } );
</script>
 
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>

<img class="zoomTarget" data-targetsize="0.05" data-closeclick="true" src="file.png">

标签自动完成并不总是有效,只有第一次,但如果我删除 zoomooz,它工作正常

4

1 回答 1

0

我无法复制您描述的问题。如果您使用 jQuery UI 自动完成,则必须使用正确的选项。这是一个工作示例。

$(function() {
  var availableTags = [
    "ActionScript",
    "AppleScript",
    "Asp",
    "BASIC",
    "C",
    "C++",
    "Clojure",
    "COBOL",
    "ColdFusion",
    "Erlang",
    "Fortran",
    "Groovy",
    "Haskell",
    "Java",
    "JavaScript",
    "Lisp",
    "Perl",
    "PHP",
    "Python",
    "Ruby",
    "Scala",
    "Scheme"
  ];

  $("#numean").autocomplete({
    source: availableTags,
    minLength: 1,
    open: function() {
      console.log("Open Triggered");
    },
    focus: function() {
      console.log("Focus Triggered");
      return true;
    },
    select: function() {
      console.log("Select Triggered");
      return true;
    }
  });

  $(".zoomTarget").zoomTo({
    duration: 1000,
    closeclick: true,
    targetsize: 0.05
  });
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zoomooz/1.1.6/jquery.zoomooz.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<input type="text" id="numean" value="">
<br />
<img class="zoomTarget" width="50%" src="https://i.imgur.com/FThOLcL.jpg">

看更多:

更新

经过一些测试,我可以看到click事件的冒泡被打乱了。例如,在上面的示例中,在第一轮中,一切都按预期进行。在第二次搜索时,您可以↓</kbd> to your selection and press Enter and focus and select is triggered. Yet if you try to move the mouse and click the item, only focus is triggered. I am pretty sure the conflict comes from the closeclick: true setting. I think this is listening on a higher scope after a Zoom then the click event for select.

我建议设置closeclick: false然后创建另一种关闭方法。按钮或其他更具体的事件。

你可能还注意到我在 jQuery 之前先加载了 Zoomooz。我注意到如果它们以其他顺序加载,就会出现一些奇怪的window冲突。

于 2019-10-18T03:52:16.803 回答