简体   繁体   English

如何在我的jquery菜单中的li项下添加一行?

[英]How would I add a line under li items in my jquery menu?

I'm not really sure where to start on this, but I have a menu done in jquery. 我不确定从哪里开始,但是我在jquery中完成了菜单。 When you hover over right now, it does some fade in/out effects to the text, and links are manually handeled. 当您将鼠标悬停在上方时,它会对文本产生一些淡入/淡出效果,并且会手动处理链接。

I wanted to add a simple line, maybe done in css? 我想添加一条简单的线,也许在CSS中完成? to go under each li a item when you are hovering as well, sliding to the li you hover over, not just appearing. 在悬停时也要在每个li下方找到一个项目,滑到悬停的li上,而不仅仅是出现。

I just have no idea where to start with something like that, as I've never really done it before without an image (preferrably). 我只是不知道从哪里开始,因为我从来没有真正做到过(最好)没有图像。 It would of coarse need to start somewhere and move alone the ul and stop wherever it is when you leave the div with your mouse, and I'd like to keep it on when you click a link. 当您用鼠标离开div时,粗略地需要从某个地方开始并单独移动ul,然后在任何地方停止,而我想在单击链接时将其保持打开状态。 I'm not asking anyone to make this for me though (unless you feel like it), just to get pointed on the right direction. 我并不是要任何人为我做这件事(除非您觉得喜欢),只是为了指出正确的方向。 I've seen some free codes with menus that do this, and attempted to use them, or model off them, but it woulnd't work with my menu. 我已经看到了一些带有菜单的免费代码,并且尝试使用它们或对其进行建模,但是它们不适用于我的菜单。

Fiddle 小提琴

I did this a while ago, maybe it is what you need. 我前一阵子做了,也许正是您所需要的。 It will calculate the width of the anchor element you are hovering and grow an underliner element (a div) to both its width and position 它将计算要悬停的锚点元素的宽度,并将下衬元素(div)增大到其宽度和位置

//underliner
$('#menu a').hover(function(){
    var position = $(this).position(); var width = $(this).width();
    $('#underliner', '#menu').animate({width: width,left: position.left}, 200 );
});
$('#menu').hover(function(){
    $('#underliner', '#menu').animate({opacity: 1}, 200).show();
}, function () {
    $('#underliner', '#menu').animate({opacity: 0}, 200).hide();
});

CSS for the underline-element (change height and bg color as you seem fit) 下划线元素的CSS(根据需要更改高度和bg颜色)

#underliner {
    display: none;
    position: relative;
    height: 5px;
    line-height: 5px;
    font-size: 1px;
    background-color: #44c8f5;
    width: 1px;
    opacity: 0;
    filter: alpha(opacity=0);
}

HTML 的HTML

<div id="menu">
    <ul>
        list items with <a href>'s
    </ul>
    <div id="underliner"></div>
</div>

edit : I tried merging it with your code, but as you did not include the html, I had to guess how your 'navibar' was laid out. 编辑 :我试图将其与您的代码合并,但由于您不包括html,因此我不得不猜测您的“导航栏”的布局方式。 Anyway, try this fiddle: http://jsfiddle.net/c_kick/DuWcz/ 无论如何,请尝试这个小提琴: http : //jsfiddle.net/c_kick/DuWcz/

暂无
暂无

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

相关问题 我想在jQuery和css中为我的菜单项添加一个子元素 - I want to add a sub element to my menu items in jQuery and css 如何使用jQuery向我的网站添加滑块过渡? - How would I add a slider transition to my website with jQuery? 如何将所有ul和li保留在父li下:selected,但删除其他导航项 - How do I keep all ul and li's under a parent li:selected, but remove other navigation items 我将如何选择列表中的最后一个 LI 并使用 jQuery 将其变为红色? - How would I select the last LI in the list and turn it red with jQuery? 我如何从一个 <li> 下拉菜单是php用JavaScript还是jquery生成了第二个li菜单? - How can I generate from a <li> drop down menu that is php generated a second li menu with javascript or jquery? 如何使用 jQuery 将活动类添加到菜单和子菜单项 - How to add active class to menu and sub menu items with jQuery 添加新商品后如何添加计数器 <li> 使用jQuery到我的列表 - How I can add a counter after adding a new <li> to my list using jquery 如何在特定“ul”元素下获取多个“li”元素并将它们放入数组中? - How would I get multiple "li" elements under a specific "ul" element and put them into an array? 添加一个href链接 <li> 使用jQuery的项目 - add a href-link to <li> items with jQuery 我怎样才能添加 '<input type="checkbox" checked> ' 属性到所有使用 jQuery 动态创建的列表项? - How can I add a '<input type="checkbox" checked>' attribute to all li dynamically created list items using jQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM