我正在使用我的wordpress网站的浮点线菜单,我得到了THIS FAR的帮助。
现在我的问题是如何将选定的导航浮动线与将鼠标悬停在菜单项上时的颜色相同?此时,只要鼠标关闭,它就会变为默认的红色。
这就是我想要实现的目标:
当菜单1被选中时(点击后),浮点线颜色应为#0f0
选择菜单2 - #ee0
选择菜单3 - #05f
感谢任何帮助。
答案 0 :(得分:1)
将var currentSelected;
添加到var sse1 = function () {
之上并将currentSelected=k;
添加到下面的块中
for (var i = 0; i < a.length; i++) {
if (url.indexOf(a[i].href.toLowerCase()) != -1 && a[i].href.length > nLength) {
k = i;
nLength = a[i].href.length;
}
}
将当前所选列表的索引推送到currentSelected
。
因此请在customHandleMenu
函数
var navigations=[
/* Nav 1 style */
{floatColor: '#0f0',
borderColor: '#0f0'},
/* Nav 2 style */
{floatColor: '#ee0',
borderColor: '#ee0'},
/* Nav 3 style */
{floatColor: '#05f',
borderColor: '#05f'},
];
function customHandleMenu() {
// get nav selector
var nav = $('#sses1 > ul');
// get float line selector
var floatLine = $('.highlight'); // .hightlight must exist at this point
// get colors for the current page
var defaultBGcolor = navigations[currentSelected]["borderColor"];
var defaultBorderColor = navigations[currentSelected]["borderColor"];
var defaultNavBorderColor = navigations[currentSelected]["borderColor"];
// change background-color and border-color on mouseenter event
$('.nav-item-1').on({
mouseenter: function () {
setColors({
floatColor: navigations[0]["floatColor"],
borderColor: navigations[0]["borderColor"]
});
}
});
$('.nav-item-2').on({
mouseenter: function () {
setColors({
floatColor: navigations[1]["floatColor"],
borderColor: navigations[1]["borderColor"]
});
}
});
$('.nav-item-3').on({
mouseenter: function () {
setColors({
floatColor: navigations[2]["floatColor"],
borderColor: navigations[2]["borderColor"]
});
}
});
/*
...
*/
// put back default colors on the mouseleave event
$('#sses1 > ul > li').on({
mouseleave: function() {
setColors({floatColor:defaultBGcolor, borderColor:defaultNavBorderColor});
}
});
setColors({floatColor:defaultBGcolor, borderColor:defaultNavBorderColor});
function setColors(args) {
if (typeof args.floatColor != "undefined") {
floatLine.css('background-color', args.floatColor);
}
if (typeof args.borderColor != "undefined") {
floatLine.css('border-color', args.borderColor);
nav.css('border-bottom-color', args.borderColor);
}
}
}
要防止Float Line动画化onload,请按照代码中注释的说明进行操作
//slip.style.left = items[k].offsetLeft + "px";
sse1.move(items[k]); //comment out this line and uncomment the line above to disable initial animation
创建:
slip.style.left = items[k].offsetLeft + "px";
// sse1.move(items[k]); comment out this line and uncomment the line above to disable initial animation.
此外,您可以选择添加
$('#sses1 li, #sses1 a').on('click',function(){
$('#sses1, #sses1 ul, #sses1 li, #sses1 a').unbind("mouseout");
$('#sses1, #sses1 ul, #sses1 li, #sses1 a').unbind("mouseleave");
$('#sses1, #sses1 ul, #sses1 li, #sses1 a').unbind("mouseenter");
$('#sses1, #sses1 ul, #sses1 li, #sses1 a').unbind("mousein");
$('#sses1, #sses1 ul, #sses1 li, #sses1 a').unbind("mouseover");
sse1={};
});
到您的customhandlemenu
功能,在页面准备加载时完全禁用任何不需要的动画。