jQuery与导航菜单上的mouseover事件冲突‮.

jQuery conflicts with mouseover event on navigation menu‮

本文关键字:mouseover 事件 冲突 导航 菜单 jQuery      更新时间:2023-09-26

我在Magento中有一个导航菜单,它在鼠标悬停时显示子类别。还有一个使用jQuery插件的倒计时。

如果我删除倒计时,菜单工作正常,但如果我添加倒计时,倒计时工作正常,但是菜单将不再在鼠标悬停上显示类别。

菜单项的代码:

<div id="menu10" class="menu popup-menu level-2" onmouseover="wpShowMenuPopup(this, 'popup10');" onmouseout="wpHideMenuPopup(this, event, 'popup10', 'menu10')">
<div class="parentMenu">
<a href="supertrash.html">
<span>SuperTrash</span>
</a>
</div>
</div>
<div id="popup10" class="popup child-2" onmouseout="wpHideMenuPopup(this, event, 'popup10', 'menu10')">
<div class="block1">
<div class="column"><div class="itemMenu level1"><a class="itemMenuName level1" href="supertrash/supertrash-rokjes.html">Rokjes</a></div></div><div class="column"><div class="itemMenu level1"><a class="itemMenuName level1" href="supertrash/stschoenen.html">Schoenen</a></div></div>
<div class="clearBoth"></div>
</div>
</div>      

鼠标悬停的javascript:

function wpShowMenuPopup(objMenu, popupId)
{
    objMenu = $(objMenu.id); var popup = $(popupId); if (!popup) return;
    popup.style.display = 'block';
    objMenu.addClassName('active');
    var popupWidth = CUSTOMMENU_POPUP_WIDTH;
    if (!popupWidth) popupWidth = popup.getWidth();
    var pos = wpPopupPos(objMenu, popupWidth);
    popup.style.top = pos.top + 'px';
    popup.style.left = pos.left + 'px';
    if (CUSTOMMENU_POPUP_WIDTH) popup.style.width = CUSTOMMENU_POPUP_WIDTH + 'px';
}

用于倒计时的jQuery插件:

<!-- jquery framework from google api -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<!-- google font-family, you can add whatever font suits you -->
<link href='http://fonts.googleapis.com/css?family=Averia+Serif+Libre:300italic' rel='stylesheet' type='text/css'>
<!-- The stylesheet -->
<link rel="stylesheet" type="text/css" href="counter2/css/style2.css">
<!-- the countdown plugin -->
<script src="counter2/coffeetime/coffeetime.min.js"></script>
<!-- The countdown style -->
<link rel="stylesheet" type="text/css" href="counter2/coffeetime/ctstyle.css">
<script>
/* here u can set up different messages for the progress of the countdown
if no message is set for the current percent value, it takes the next message, bigger or equal to that percentage
*/
var message = new Array();
message[0] = "status: just started";
message[10] = "status: drinking a coffe";
message[20] = "status: just finished setting up the database";
message[30] = "status: brainstorming about the template";
message[50] = "status: choosing the color scheme";
message[80] = "status: thinking about the future";
message[90] = "status: nearly done";
message[100] = "status: finished";
$(document).ready(function() {
function callback() {
    alert("Sale is over");
}

$("#flipit").coffeetime({
                        /* COUNTDOWN SETTINGS */
                        message: message, // the message array with the array keys as percent values
                        startYear: 2012,
                        startMonth: 8,
                        startDay: 30,
                        endYear: 2012,
                        endMonth: 9,
                        endDay: 7,
                        callbackFinish : callback,
                            });
$(".flip-title-subheading").html(" we started on "+ window.startDate+ " and we`ll finish on "+ window.endDate);
});
$(document).ready(function () {
    setTimeout(function () {
        $(".flip-container").animate({
            "height" : 105 + "px"
        }, 1000, "swing");
    }, 1000);
});
</script>

我试过几种方法:

  • 在标题中还有一个(旧的(1.4.3))版本的jQuery,试图用1.8.0版本替换它,但什么都不起作用

  • 我试着删除了倒计时中包含的1.8.0版本,当时菜单工作正常,但没有倒计时

  • 我试过使用jQuery.noConflict()进行倒计时,菜单一直在工作,但倒计时没有

我不知所措,我希望有人知道我做错了什么,谢谢!

我会告诉您尝试noConflict(),但您已经尝试过了。所以,试着为jQuery更改$,这个garantee magento使用了正确的JS,因为z原型也使用了$。如果不起作用,在你的页面上寻找做同样事情的2个JS脚本。移除是一个。

添加鼠标悬停功能作为

jQuery.noConflict();
function wpShowMenuPopup(objMenu, popupId)

objMenu = jQuery(objMenu.id); var popup = jQuery(popupId); if (!popup) return;
popup.style.display = 'block';
objMenu.addClassName('active');
var popupWidth = CUSTOMMENU_POPUP_WIDTH;
if (!popupWidth) popupWidth = popup.getWidth();
var pos = wpPopupPos(objMenu, popupWidth);
popup.style.top = pos.top + 'px';
popup.style.left = pos.left + 'px';
if (CUSTOMMENU_POPUP_WIDTH) popup.style.width = CUSTOMMENU_POPUP_WIDTH + 'px';

}

希望这能有所帮助!!

毕竟是noConflict()。

在倒计时脚本之前添加以下内容

var $c = jQuery.noConflict(); 

并且在$c倒计时中更改所有$变量是有效的。

我在noConflict中使用了$i$j变量(它们在前面声明过),但制作一个新的变量很神奇。谢谢大家!