简体   繁体   English

jQuery Hover在Wordpress网站上不起作用

[英]jQuery Hover not working on Wordpress site

I posted this question about toggling DIV visibility earlier today and received the correct answer which works perfectly as you can see in this Fiddle . 我今天早些时候发布了有关切换DIV可见性的问题 ,并且收到了正确的答案,正如您在本小提琴中所看到的那样,该答案非常有效。

I'm basically trying to toggle div visibility on repeating classes with jQuery hover. 我基本上是想在jQuery悬停的重复类上切换div可见性。

The problem is, I can't get it working on my Wordpress site. 问题是,我无法在我的Wordpress网站上使用它。

The jQuery just isn't firing at all even though all of the div's and CSS is present and correct. 即使所有的div和CSS都存在且正确,jQuery根本不会触发。 There are no error's being reported in the console at all. 控制台中完全没有错误报告。 It's just not loading this function. 它只是不加载此功能。

I must be calling it incorrectly! 我一定叫错了!

FYI - WP site is loading jQuery 1.11.0 and jQuery.migrate 1.2.1. 仅供参考-WP网站正在加载jQuery 1.11.0和jQuery.migrate 1.2.1。

The jQuery exactly how it is located in the footer of the site (wrapped due to compatibility mode) : jQuery确切地位于网站页脚的位置(由于兼容模式而被包装):

 <script type="text/javascript">

 (function($) {
   $(".showlist-wrap").hover(function() {
   $(".showlist-artwork,.showlist-info",this).toggle().off("hover");
 });
 })( jQuery );

 </script>

The CSS looks like this : CSS看起来像这样:

 .showlist-wrap {
   position:relative;
   width:293px;
   height:195px;
   background:black;
   margin-right:13px;
   margin-bottom:13px;
   float:left;
   border-radius:10px;
   overflow:hidden;
 }

 .showlist-artwork {
   position:absolute;
   top:0;
   width:293px;
   height:195px;
   display:block;
 }

 .showlist-info {
   position:absolute;
   top:0;
   width:293px;
   height:195px;
   display:none;
 }

The HTML fires like this : HTML触发如下:

 <div class="showlist-wrap">
 <div class="showlist-artwork"><img src="/image.jpg" /></div>
 <div class="showlist-info">Some Text Goes Here</div>
 </div>

Like I mentioned above, the actual CSS is displaying perfectly on the page and everything HTML wise is where it should be. 就像我在上面提到的那样,实际的CSS可以完美地显示在页面上,而所有HTML明智的地方都应该显示在CSS上。 It's just the jQuery not working so the code must be incorrect. 只是jQuery无法正常工作,因此代码必须不正确。

Could somebody show me where I'm going wrong please? 有人可以告诉我我要去哪里了吗?

The wordpress autoloads the jquery, so if you included the jquery manually in your theme the jquery is loaded twice and this could create a conflict. WordPress会自动加载jquery,因此,如果您在主题中手动包含了jquery,jquery将被加载两次,这可能会产生冲突。

Please read this article about including js and css properly 请阅读文章有关,包括JS和CSS正确

Probably it is because you're not waiting for DOM ready before binding the event, and you cannot use .off() if you did not use .on() to bind the event: 也许这是因为你不等待DOM ready绑定事件之前,你不能使用.off()如果你没有使用.on()来绑定事件:

$(function(jQuery) {
    (function($) {
        $(".showlist-wrap").on('hover', function() {
            $(".showlist-artwork,.showlist-info",this).toggle().off("hover");
        });
    })( jQuery );
});

Or the content you're binding this event handler to may not be available at DOM ready : 否则,绑定此事件处理程序的内容可能在DOM ready不可用:

(function($) {
    $(document).on('hover', ".showlist-wrap", function() {
        $(".showlist-artwork,.showlist-info",this).toggle().off("hover");
    });
})( jQuery );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM