【问题标题】:jquery hover works for only certain divsjquery hover 仅适用于某些 div
【发布时间】:2012-10-30 09:43:06
【问题描述】:

我有 jquery carousel,我正在尝试为所有 div 实现悬停 但它只适用于某些 div 你能告诉我为什么它不适用于其他 div... 当您单击绿色和红色按钮时,您可以看到轮播运动......

http://jsfiddle.net/9Dr7T/14/

在下面提供我的 js 代码

$(".specialHover").hover(
  function () {
        //  $("<div class='cta'>add image</div>").click(function() {
    $("<div class='cta'>add image</div>").click(function() {
        $(this).parent().unbind("hover").children("img").attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");
        $(this).remove();
    }).appendTo(this);
  }, 
  function () {
    $(this).find("div:last").remove();
  }
);

【问题讨论】:

标签: jquery-ui jquery jquery-plugins jquery-selectors


【解决方案1】:

只需将代码的最后一行注释如下:

$(".specialHover").hover(
  function () {
        //  $("<div class='cta'>add image</div>").click(function() {
    $("<div class='cta'>add image</div>").click(function() {
        $(this).parent().unbind("hover").children("img").attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");
        $(this).remove();
    }).appendTo(this);
  }, 
  function () {
    //$(this).find("div:last").remove();
  }
);

//$(this).find("div:last").remove();

【讨论】:

  • @SEMSEM:感谢您的回复,但后来当我从 div 中出来时,它应该会消失,它不应该永久存在jsfiddle.net/9Dr7T/17/embedded/result
  • 通过这种方式你必须使用mouseout事件来隐藏它或尝试制作或使用另一个选择器。
  • 你能在小提琴中更新它吗...我没有得到它....jsfiddle.net/9Dr7T/17
  • 你能把 div 的高度从 5 降低到 9 吗?您的问题似乎是“添加图像”的渲染!或使“添加图像”在顶部呈现。
  • @semsem: 你能告诉我是否需要降低css或jquery中的高度
猜你喜欢
  • 2014-02-03
  • 1970-01-01
  • 1970-01-01
  • 2021-12-26
  • 2013-06-24
  • 2012-05-19
  • 2015-10-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多