1

我正在创建我的投资组合网站。我希望在准备好文档时添加类,并在悬停时将该类删除/更改为不同的类。我在加载和悬停时对我的图像使用 lightgallery 和 CSS gram 过滤器。之前,我添加了一个列表。不幸的是,它不能很好地满足我的需求。以前的代码

$("#gallery a").on({
  mouseenter : function() {
    $(this).find(".nak-gallery-poster").removeClass("inkwell").addClass("mayfair");
  },
  mouseleave : function() {
    $(this).find(".nak-gallery-poster").removeClass("mayfair").addClass("inkwell");
  }
}); 

我更改了 jQuery 以匹配之前代码中的内容。这没有用。请帮忙。我的代码笔

4

3 回答 3

3

删除代码

$lg.lightGallery();
  $lg.append(slide);
  $lg.data('lightGallery').destroy(true);
  $lg.lightGallery(); 

从你的codepen,然后一切正常

好像你错过了一些插件或放置了错误的代码

于 2017-01-13T05:56:12.263 回答
0

而不是像这样使用两个类编辑你的CSS

.inkwell{
color: red;
}
.inkwell:Hover{
color: blue
}

这比 jquery 更容易且不那么混乱,您可以根据需要添加背景颜色和所有您想要的东西

于 2017-01-13T05:49:51.713 回答
-4

嗨,我在 codepen 中查看了您的代码,发现您没有在 document.ready(function(){ ... } 中包含 mouseenter 和其他方法方法。我想将此作为评论发布,但他们不会让我这样做是因为我的代表点数少于 50。

请在 document.ready 中添加这些代码,它们会正常工作。事件不会被注册,因为脚本在 DOM 加载之前被执行。

是的,$lg 也是未定义的,但其他人提到了它,所以我离开了它。现在添加。

于 2017-01-13T06:00:00.543 回答