【问题标题】:Issues with .focus in firefoxFirefox 中的 .focus 问题
【发布时间】:2016-05-26 02:12:07
【问题描述】:

我正在构建这个自定义布局,并且我在 Firefox 上遇到了一些奇怪的事情。

如您所见,无论是通过选项卡还是在 Firefox 上单击鼠标,图像都无法聚焦。这在 Chrome 上运行良好。它们确实需要是图像,因为最终产品将是 svg,并且它们都需要可点击且可通过键盘访问!

Here's a link to my page.

这是我的 JS 代码

if ( jQuery(window).width() > 900) {
//Execute only when width is greater than 900px

 var circles = document.getElementsByClassName("js-circle"),
     text = document.getElementsByClassName("js-text"),
     buttons = document.getElementsByClassName("js-button");

  for (var i = 0; i < circles.length; i++) {
    console.log("assign listeners");
    assignListeners(i);
  }

  function assignListeners(i) {
    (function(i) {
      circles[i].addEventListener('focus', function(e) {
        console.log(circles[i]);
        reveal(e, i);
      }, false);
      buttons[i].addEventListener('blur', function(e) {
        hide(e, i);
      }, false);
    }(i));
  }

  function reveal(e, i) {
    jQuery(text[i]).fadeIn();

  }

  function hide(e, i) {
    jQuery(text[i]).fadeOut();
  }

}

【问题讨论】:

    标签: javascript jquery html css firefox


    【解决方案1】:

    原来问题不在于 Firefox,而在于 Mac OSX。显然,如果您的系统偏好设置中没有完整的键盘访问权限,那么 Firefox 将不会跳转到任何不是链接的内容。

    【讨论】:

    【解决方案2】:

    如果您将属性tabindex 设置为img 标记并使用css 选择器+,也许您可​​以跳过jquery。


    基本上是img HTML:

    <img tabindex="0" src="http://kathrynjcrawford.com/testimg.png" class="deg180 || svg-circle || js-circle" tabindex="0">
    

    和 CSS :

    img:focus + .text-container {
      display:block;
    }
    

    DEMO sn -p 运行整页

    .bg-container {
      width: 100%;
      margin: 0;
      background: linear-gradient(to bottom, #a7a7a7 0%, #dadada 100%);
    }
    /* neatly spaced stuff for mobile */
    
    .img-container {
      align-items: center;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }
    .svg-circle {
      background: white;
      border-radius: 50%;
      height: 6em;
      margin-top: 2em;
      width: 6em;
    }
    .svg-circle:focus {
      background: red;
    }
    .text-container {
      color: #e92837;
      text-align: center;
      max-width: 15em;
    }
    .text-container p {
      color: #025a83;
    }
    .services-button {
      background: #e92837;
      border: none;
      color: #ffffff;
      font-family: Myriad Pro;
      font-size: 18px;
      margin-bottom: 2em;
      padding: 13px 20px 12px 20px;
      text-decoration: none;
    }
    .services-button:hover {
      text-decoration: none;
    }
    @media screen and (min-width: 900px) {
      /* centers the image container and constrains proportions */
      .img-container {
        height: 50%;
        margin: 1.75em auto 0;
        min-height: 900px;
        padding: 2.8em;
        position: relative;
        width: 50%;
      }
      /* sets circles up in center of img-container to prepare for translations */
      .svg-circle {
        display: block;
        left: 50%;
        margin: -3em;
        position: absolute;
        top: 50%;
      }
      /* positions all text containers in the center of the img-container */
      .text-container {
        display: none;
        left: 0;
        margin-left: auto;
        margin-right: auto;
        margin-top: 10em;
        max-width: 15em;
        position: absolute;
        right: 0;
      }
      /* TRANSLATIONS */
      .deg0 {
        transform: translate(23em);
      }
      .deg30 {
        transform: rotate(-30deg) translate(23em) rotate(30deg);
      }
      .deg60 {
        transform: rotate(-60deg) translate(24em) rotate(60deg);
      }
      .deg90 {
        transform: rotate(-90deg) translate(25em) rotate(90deg);
      }
      .deg120 {
        transform: rotate(-120deg) translate(24em) rotate(120deg);
      }
      .deg150 {
        transform: rotate(-150deg) translate(23em) rotate(150deg);
      }
      .deg180 {
        transform: rotate(-180deg) translate(23em) rotate(180deg);
      }
    }
    img:focus + .text-container {
      display: block;
    }
    <div class="bg-container">
      <div class="img-container">
        <img tabindex="0" src="http://kathrynjcrawford.com/testimg.png" class="deg180 || svg-circle || js-circle" tabindex="0">
    
        <div class="text-container || js-text">
          <h2>Service 1</h2>
          <p>I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--</p>
          <button class="js-button" type="button">Learn More</button>
        </div>
    
        <img tabindex="0" src="http://kathrynjcrawford.com/testimg.png" class="deg150 || svg-circle || js-circle" tabindex="0">
    
        <div class="text-container || js-text">
          <h2>Service 2</h2>
          <p>I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--</p>
          <button class="js-button" type="button">Learn More</button>
        </div>
    
        <img tabindex="0" src="http://kathrynjcrawford.com/testimg.png" class="deg120 || svg-circle || js-circle" tabindex="0">
    
        <div class="text-container || js-text">
          <h2>Service 3</h2>
          <p>I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--</p>
          <button class="js-button" type="button">Learn More</button>
        </div>
    
        <img tabindex="0" src="http://kathrynjcrawford.com/testimg.png" class="deg90 || svg-circle || js-circle" tabindex="0">
    
        <div class="text-container || js-text">
          <h2>Service 4</h2>
          <p>I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--</p>
          <button class="js-button" type="button">Learn More</button>
        </div>
    
        <img tabindex="0" src="http://kathrynjcrawford.com/testimg.png" class="deg60 || svg-circle || js-circle" tabindex="0">
    
        <div class="text-container || js-text">
          <h2>Service 5</h2>
          <p>I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--</p>
          <button class="js-button" type="button">Learn More</button>
        </div>
    
        <img tabindex="0" src="http://kathrynjcrawford.com/testimg.png" class="deg30 || svg-circle || js-circle" tabindex="0">
    
        <div class="text-container || js-text">
          <h2>Service 6</h2>
          <p>I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--</p>
          <button class="js-button" type="button">Learn More</button>
        </div>
    
        <img tabindex="0" src="http://kathrynjcrawford.com/testimg.png" class="deg0 || svg-circle || js-circle" tabindex="0">
    
        <div class="text-container || js-text">
          <h2>Service 7</h2>
          <p>I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--</p>
          <button class="services-button || js-button" type="button">Learn More</button>
        </div>
    
      </div>
    
    </div>

    从 chrome 渲染的角度来看,在这一点上对我来说似乎没有那么多问题 :)

    【讨论】:

    • 好吧,Firefox 忽略了 :focus 选择器,所以不,这也不起作用。
    • @KathrynCrawford : 没有 tabindex 的焦点选择器不起作用(仅在链接或表单元素上),sn-p 与 FF 一起使用。你有一个不起作用的例子吗?除了我用 Firefox 创建的 sn-p 之外(我用 :focus 和 tabindex 玩了几年)?
    • @KathrynCrawford dabblet.com/gist/2906473 一个实验性的 2 级菜单,通过 tabindex 和 :focus(根本没有 js)用 FF 和近 5 年前制作...在点击或 Tab 键上工作
    • 看我的回答。实际上并不是firefox导致了这个问题。这是 Mac OS 系统偏好设置...
    • @KathrynCrawford 实际上,OP 的 javascript 代码仅适用于我的 chrome 和 Opera,不适用于 firefox :)(WIN OS)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 2011-10-26
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    相关资源
    最近更新 更多