【问题标题】:Wordpress menu-item-hoverWordpress 菜单项悬停
【发布时间】:2014-03-24 15:03:12
【问题描述】:

我正在尝试创建自定义下拉菜单。

我的代码如下:

<div id="header"> </div>

      <div class="layer1_col">
        <?php wdg::displayMenu('main'); ?>
      </div>

      <div class="programmingTable"></div>
      <div id="main">

wdg::displayMenu('main');显然,生成在 wordpress 后端创建的菜单,称为“main”。没有改变wdg,因为我需要使用它。

我正在尝试编辑 menu-item-12,当我在 chrome 中编辑网站时,这就是菜单的构建方式(这就是我进入 menu-item-12 的方式)。

<ul id="menu-main" class=""><li id="menu-item-96" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-96"><a href="http://jouwfm.100200.nl/">NIEUWS</a></li>
<li id="menu-item-103" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-103"><a href="http://jouwfm.100200.nl/archief/">ARCHIEF</a></li>
<li id="menu-item-12" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-12"><a>PROGRAMMERING</a></li>
<li id="menu-item-97" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-97"><a href="http://jouwfm.100200.nl/vacatures/">VACATURES</a></li>
<li id="menu-item-102" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-102"><a href="http://jouwfm.100200.nl/adverteren/">ADVERTEREN</a></li>
<li id="menu-item-27" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-27"><a href="http://jouwfm.100200.nl/contact/">CONTACT</a></li>
</ul>

而 menu-item-12 并不是真正的菜单项。它没有连接到它的链接,div(.programmingTable)将被所有不同的帖子填充,但这是问题所在)。

我的 CSS 看起来像:

.programmingTable{
  display:none;
  margin-left: 10px;
  margin-right: 10px;
  padding: 0;
  height: 380px;
  line-height: 1.5em;
  background-color: #e3e3e3;
  position: absolute;
  z-index: 5;
  width: 934px;
  top: 87px;
  padding-left: 8px;
  padding-right: 8px;
  padding-top: 45px;
  border-bottom-left-radius: 8px;
  -moz-border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  -moz-border-bottom-right-radius: 8px;
  -webkit-box-shadow: 0 7px 9px rgba(50,50,50,0.41);
  -moz-box-shadow: 0 7px 9px rgba(50,50,50,0.41);
  box-shadow: 0 7px 9px rgba(50,50,50,0.41);
  background: -webkit-gradient(linear,0% 0,0% 90%,from(#d9d9d9),to(#fbfbfb));
  background: -webkit-linear-gradient(top,#d9d9d9,#fbfbfb);
  background: -moz-linear-gradient(top,#d9d9d9,#fbfbfb);
  background: -ms-linear-gradient(top,#d9d9d9,#fbfbfb);
  background: -o-linear-gradient(top,#d9d9d9,#fbfbfb);
}

#menu-item-12:hover .programmingTable{
  display:block;
}

还尝试使用不透明度、z-index。 z-index 可以工作的地方,但 div 的其余部分不是相同的颜色。它看起来不正确。

我已经尝试使用 jquery 来实现它:

  jQuery('#menu-item-12').mouseover(

    jQuery(document).ready( function() {
      jQuery('.programmingTable').fadeIn(200)
    })
  );
  jQuery('#menu-item-12').mouseleave(

    jQuery(document).ready( function() {
      jQuery('.programmingTable').fadeOut(200)
    })
  );

这不起作用。好吧,我猜是一半。它使项目在页面加载时淡入然后再次淡出。将鼠标悬停在有问题的 div 上时,它不会执行任何操作。

我已经被这个问题困扰了几天,任何帮助将不胜感激。

关于我的意思的一个更好的例子是this site 将鼠标悬停在“编程”上。

编辑:这是 displayMenu 上的类

 static public function displayMenu( $name, $atts=array( ))
{
  // Getting/Setting the variablen
  extract( shortcode_atts( array( 'container'      => 'div',
                                  'containerid'    => '',
                                  'containerclass' => '',
                                  'menuid'         => '',
                                  'menuclass'      => '',
                                  'afterlabel'     => '',
                                  'beforelabel'    => '',
                                ), $atts
         ));

  wp_nav_menu( array( 'menu'            => $name,
                      'menu_id'         => $menuid,
                      'menu_class'      => $menuclass,
                      'link_before'     => $beforelabel,
                      'link_after'      => $afterlabel,
                      'container'       => $container,
                      'container_id'    => $containerid,
                      'container_class' => $containerclass,
                    ));
}

【问题讨论】:

  • 是下拉菜单悬停的问题吗?
  • @James 没有下拉菜单,只有一个需要在悬停时显示的 div。

标签: php jquery css wordpress menu


【解决方案1】:

我很确定你的 jQuery 代码可以工作。

它是在 .ready 事件中调用的吗?

另外,我会使用 .mouseenter 事件。

jQuery(document).ready(function() {
    jQuery('#menu-item-12').mouseenter(function() {
        doSomething();
    }).mouseleave(function() {
        doSomethingElse();
    });
})

【讨论】:

  • 你能用新版本的 html 和 jquery 更新你的帖子吗?
  • 你是什么意思?没有新版本,我用wordpress生成的html
猜你喜欢
  • 2015-01-03
  • 1970-01-01
  • 1970-01-01
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多