在mouseout上更改颜色'a'标记

时间:2015-01-23 18:15:04

标签: jquery html css

Hello堆栈溢出社区,

我正在为博物馆建造这个WW2网站,并创建了这个响应式标题。当它小于800px时,会发生以下情况。

当我点击' foto' s'当时的博物馆40-45'子菜单出现,但当我将鼠标悬停在子菜单上时,a标签会跳回绿色状态。

如何让这个标签变成白色,让它在盘旋U'时保持白色?

这是我使用的jquery

$(document).ready(function(){

    $(function() {
        FastClick.attach(document.body);
    });

    var contador = 1;

    $('.menu_bar').on('click', function(event){

        event.stopPropagation();

        if (contador == 1) {
        $('nav').animate({
        left: '0'
        });
        contador = 0;
        }   

        else {
            contador = 1;

            $('nav').animate({
            left: '-100%'});

            };
        });

    $('.submenu').on('click', function(event){
        event.stopPropagation();
        $(this).children('.children').slideToggle();
    });

    if($(window).width()<800){
            $('video').get(0).pause();
            $('#headVideo').remove();
        }

});

这里是css

.contentWrapper {
  position: relative;
  max-width: 900px;
  margin: 0 auto; }

.home .fallBackPicture {
  max-width: 900px;
  height: 450px;
  background-color: #ccc; }
  .home .fallBackPicture video {
    width: 100% !important;
    height: auto !important; }

.menu_bar {
  display: none;
  height: 51px;
  cursor: pointer; }

header {
  width: 100%; }
  header .headerPic {
    background: url(../img/HeaderPic.jpg) center center;
    background-size: cover; }
    header .headerPic .logo {
      padding: 0 10px 35px 10px; }
      header .headerPic .logo svg {
        fill: red;
        width: 100%; }
  header nav {
    padding: 20px 10px 0px 10px;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    cursor: pointer;
    background: #2B460B;
    z-index: 1000;
    max-width: 100%;
    margin: 0 auto;
    margin-bottom: 0px;
    margin-top: 0px; }
    header nav ul {
      position: relative;
      background-color: #2B460B;
      background-image: -webkit-linear-gradient(#2B460B, #1E1E1E);
      background-image: linear-gradient(#2B460B, #1E1E1E);
      width: 100%;
      margin-bottom: 0px;
      margin-top: 0px;
      margin: 0 auto;
      text-align: center;
      list-style: none;
      padding-left: 0px; }
      header nav ul li {
        text-transform: uppercase;
        display: inline-block;
        position: relative;
        font-weight: 400;
        font-style: italic; }
        header nav ul li:hover {
          background: #2B460B; }
        header nav ul li a {
          color: white;
          display: block;
          text-decoration: none;
          padding: 10px; }
          header nav ul li a span {
            float: right;
            margin-right: 5px;
            margin-left: 12px; }
        header nav ul li:hover .children {
          display: block; }
          header nav ul li:hover .children ul {
            display: none;
            left: 100%;
            top: 0; }
        header nav ul li .children {
          text-align: left;
          display: none;
          background: rgba(43, 70, 11, 0.5);
          position: absolute;
          width: 250%;
          z-index: 1000;
          padding-left: 0px; }
          header nav ul li .children li {
            display: block;
            border-bottom: 1px solid rgba(255, 255, 255, 0.5); }
            header nav ul li .children li a {
              display: block; }
              header nav ul li .children li a span {
                float: right;
                position: relative;
                top: 3px;
                margin-right: 0;
                margin-left: 10px; }
        header nav ul li .caret {
          position: relative;
          top: 3px;
          margin-left: 10px;
          margin-right: 0px; }

@media screen and (max-width: 800px) {
  .menu_bar {
    display: block;
    width: 100%;
    position: fixed;
    top: 0;
    background: #2B460B; }
    .menu_bar .bt_menu {
      display: block;
      color: white;
      overflow: hidden;
      font-size: 25px;
      font-weight: bold;
      text-decoration: none;
      float: right;
      padding: 10px; }
      .menu_bar .bt_menu svg {
        fill: white;
        width: 25px;
        height: 25px; }

  header .headerPic {
    display: none; }

  header nav {
    padding: 0px 0px 0px 0px;
    border-top-left-radius: 0px;
    border-top-right-radius: 0px;
    background: rgba(43, 70, 11, 0.7);
    width: 80%;
    height: calc(100% - 80px);
    position: fixed;
    right: 100%;
    margin: 0;
    top: 51px;
    overflow: scroll; }
    header nav .level-1 {
      margin-left: 2px;
      padding-left: 0px;
      margin-top: 0px;
      padding-right: 0px;
      background-color: transparent;
      background-image: none;
      background-repeat: no-repeat;
      filter: none; }
    header nav ul li {
      text-align: left;
      display: block;
      border-bottom: 1px solid rgba(255, 255, 255, 0.5); }
      header nav ul li a {
        display: block; }
      header nav ul li:hover .children {
        display: none; }
      header nav ul li .children {
        background: white;
        width: 100%;
        position: relative; }
        header nav ul li .children li a {
          margin-left: 5px; }
      header nav ul li #first_submenu a {
        color: #2B460B; }
        header nav ul li #first_submenu a:hover {
          color: white; }
      header nav ul li .caret {
        float: right; }
      header nav ul li:hover .children ul {
        left: 0;
        top: 0; } }
@media screen and (max-width: 480px) {
  header nav {
    width: 100%; } }

这是FIDDLE

2 个答案:

答案 0 :(得分:2)

您的子菜单点击功能缺少preventDefault动作。没有它,您的页面将跳回屏幕顶部。试试这个:

$('.submenu').on('click', function(event){
    event.stopPropagation();
    event.preventDefault();
    $(this).children('.children').slideToggle();
});

另请注意,这会阻止您的网页在任何地方导航,因此只能将其应用于<a href="#">代码。

if($(this).attr("href") != "#"){
  event.preventDefault();
}

这是小提琴:

JSFiddle

希望有所帮助!

修改

请注意,这只是问题的一半。现在看看其余的,但没有很多运气......

答案 1 :(得分:0)

尝试强制a:访问过的风格

header nav ul li a:visited {
      color: white;
      display: block;
      text-decoration: none;
      padding: 10px; }