码迷,mamicode.com
首页 > 编程语言 > 详细

[HTML5] Focus management using CSS, HTML, and JavaScript

时间:2017-02-23 20:41:10      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:absolute   cli   rem   link   which   context   man   something   opp   

Something important to consider when coding a web application is managing the user‘s focus. For keyboard and screen reader users, we must ensure their focus is not dropped as content is deleted or shown in new contexts. Skip links also provide a way for users to get past a lot of content. In this lesson, you‘ll learn HTML, CSS and JavaScript techniques for focus management that can be applied to many situations.

 

For example, you have a list of items, when you want to delete an item, you and want auto foucs on next item‘s delete button.

All what you need to do is to find next item, and send focus onto it.

    $(.btn-delete).on(click, function() {
        $(this).parent().remove();
        listItems.find(.btn-delete).first().focus();
    });

 

Next thing if you want the items which are out of foucs managmenet not to have the outline when you nav around the page.

[tabindex="-1"] {
    outline: 0;
}

 

To build a skip links: It hidden by default, but when we use Tab keyboard, it will shows up.

  <ul class="skip-links">
    <li><a href="#main">Main content</a></li>
    <li><a href="#footer">Global footer</a></li>
  </ul>
ul.skip-links {
    list-style: none;
    position: absolute;
}
    ul.skip-links a {
        background-color: #fff;
        display: block;
        left: -999999px;
        padding: 1em;
        position: absolute;
    }
    ul.skip-links a:focus {
        left: 0;
    }

 

[HTML5] Focus management using CSS, HTML, and JavaScript

标签:absolute   cli   rem   link   which   context   man   something   opp   

原文地址:http://www.cnblogs.com/Answer1215/p/6435155.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!