简体   繁体   English

保持悬停在链接上的效果

[英]Retain hover over effect on link

I have 5 links which act as a bit of a navigation bar, they are a light blue to start with, when one of them is hovered over or clicked I would like them to change color and retain that color until another link is selected. 我有5个链接,有点像导航栏,它们都是浅蓝色,当其中一个悬停或单击时,我希望它们更改颜色并保留该颜色,直到选择了另一个链接。

I have had a good search for a solution and there are many but they all seem to be for a particular case and I just can't seem to adapt them. 我一直在寻找一个好的解决方案,尽管有很多,但是它们似乎都是针对特定情况的,我似乎无法适应它们。

Any help would be greatly appreciated. 任何帮助将不胜感激。

heres my html here, I have a css file making it look pretty as well. 这是我的html,我有一个CSS文件,使其看起来也很漂亮。

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">

<head>


  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

  <script>

  $(function() {

    $( "#tabs" ).tabs({

      event: "mouseover"

    });

  });


  </script>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Menu bar</title>
<style type="text/css" />
</style>

  <link href="navPanelStyle.css" rel="stylesheet" type="text/css" />

</head>

<body>

 <div id="tabs">

  <div id="topBar">
  <ul>

    <li><a href="#Booking">BOOKINGS</a></li>

    <li><a href="#Rooms">ROOMS</a></li>

    <li><a href="#news">NEWS</a></li>

    <li><a href="#Specials">SPECIALS</a></li>

    <li><a href="#About_us">ABOUT US</a></li>

  </ul>
  </div>
<div id="content_Wrapper">
  <div id="Booking">

<p>Bookings</p>
  </div>

  <div id="Rooms">

<p>Rooms</p>
  </div>

  <div id="news">


<p>news</p>
  </div>


  <div id="Specials">

<p>Specials</p>

  </div>



  <div id="About_us">

<p>About us</p>

  </div>


</div>
</div>


</body>

</html>

If you can use Jquery to do this you can try this way, to retain a style for selected tab. 如果可以使用Jquery进行此操作,则可以尝试这种方式,以保留选定标签的样式。

Demo 演示

JS JS

$("#tabs").tabs({

    event: "mouseover",
    select: function (event, ui) {

        $('.active').removeClass('active');
        $(ui.tab).addClass('active'); // ui.tab in the select event will be currently selected tab.

        // Do stuff here
    }

});

Css CSS

#tabs .active {
    color:Blue;
}

if you want to apply over the entire tabe you can apply your styles to li tab element as follows:- 如果要应用于整个Tabe,则可以将样式应用于li tab元素,如下所示:

$(ui.tab).closest('li').addClass('active');

Demo2 DEMO2

You need to set up a piece of hover-over listener JavaScript code that removes active class from the element that was last activated and add it to the one that's hovered over. 您需要设置一个悬停侦听器JavaScript代码,以从上一次激活的元素中删除活动类,并将其添加到悬停的元素中。

Like the following: 如下所示:

$(".menuitem").hover(
    function() {
        $(this).addClass("active_menuitem");
    },
    function() {
        $(this).removeClass("active_menuitem");
    }
)

A menuitem can be anything that the CSS related to the active menu item class can be applied to menuitem可以是与活动菜单项类相关的CSS可以应用于的任何东西

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM