2017-02-28 51 views

回答

0

爲了識別您所在的頁面,可能更容易在body類中輸出itemId參數,因此編輯您的模板主文件(通常爲/templates/something/index.php)並找到<body標記,然後像這樣更改它:

<body class="your other classes here <?php 
    $app = JFactory::getApplication(); 
    $menu = $app->getMenu()->getActive()->id; 
    echo "pageid-$itemId" 
?>" 

這將呈現爲

<body class="your other classes here pageid-1302"> 

然後,假設你的頁面要引進此修復程序到具有的itemId 1302,你可以簡單地用它來定位導航作爲一個自定義的CSS規則要求:

body.pageid-1302 nav.main > ul > li:nth-child(3):hover > ul > li:nth-child(2) { 
    display:none; 
} 

(注意:這只是一個例子,我沒有你的課,你必須找到正確的路徑只針對子菜單的想法。 另外,請確保您使用手機進行測試,因爲有時類別不同。

此解決方案不使用腳本;如果您希望隱藏的子菜單是懸停的項目的子項,它將很容易工作;但是如果項目位於其他地方,則確實需要腳本。在這種情況下,你需要的功能附加到懸停事件,並採取相應的行動:假設jQuery是可用:

jQuery(function() { 
    // now the document is loaded 
    jQuery('.firstmenuselector').on('hover',function() { 
    // the user hovered the element; 
    jQuery('.submenuselector').hide(); 
    },function() { 
    // the user exited the element; 
    jQuery('.submenuselector').show(); 
    }); 
}); 

最後,你可能要添加一個類所涉及的菜單項,所以它將更容易與一個CSS或jQuery選擇器的目標。

+0

非常感謝你,我會試試這個解決方案。 –