屏幕阅读器的可访问性

时间:2017-10-08 10:56:23

标签: javascript jquery accessibility

如何使用jquery使屏幕阅读器看不到div的一部分? 我试图在某些文本上实现readmore readless功能但我面临屏幕阅读器的问题,但我必须允许accessibilty在这里。 这是我的代码,我将根据行数显示我的div的一部分:

$(document).ready(function() {
 var divHeight,l=3;
 $('.comment').each(function() {
 var $this = $(this),divHeight;
 var $content = $this.find(".text-content"),
   lineHeight= $content.css('line-height');
   divHeight= ((parseInt(l)+3)*parseInt(lineHeight))+"px";
   if($content.hasClass("short-text")){
      $content.css("height","auto");
   }
   else{
    $content.addClass("short-text");
    $content.css("overflow","hidden");
    $content.css("height",divHeight);
    $content.on("focus",function(){
      $(this).attr('aria-hidden', 'false');
    })
   }
   html='<p class="'+'para'+'"><a href="#" class="morelink morelinkStyle">' + 'more' + '</a></p></span>';
   $this.append(html);
 });
 $(".morelink").click(function(){
    var $this = $(this),
    $elem=$this.parents().find(".text-content");
    if ($elem.hasClass("short-text")) {
        $elem.removeClass("short-text");
        $this.html('less');
        divHeight = $elem.height();
        $elem.css("height","auto");
    } else {
        $elem.addClass("short-text");
        $elem.on("focus",function(){
            console.log($(this));
            $(this).css("border","2px solid red");
      $(this).attr('aria-hidden', 'false');
       })
        $this.html('more');
        $elem.css("height",divHeight);
        $elem.css("overflow","hidden");
    }
    return false;
    });

HTML正在:

<div class="comment">
<article class="text-content">
   <h3>Bedspreads</h3>
<p>Bedspreads add an elegant, ornamental look to any <a href="/store/category/bedding/10504/">bedroom</a>. They may just sit atop your bed but the right spread can pull an entire room together and create a central focal point to your bedroom. That's why Bed Bath &amp; Beyond offers a large array of bedspreads and comforters to help you find exactly what you are looking for. Wow any visitor or guest with a beautiful,</p> <p>1st para -vibrant floral pattern that brightens up any room, create a bold look with solid colors and modern styling or bring in a traditional design with classic chenille patterns. Turn your room into a viewing experience today with our ever-growing selection.Ut enim ad minim veniam,
</p>
<p>2nd para-vibrant floral pattern that brightens up any room, create a bold look with solid colors and modern styling or bring in a traditional design with classic chenille patterns. Turn your room into a viewing experience today with our ever-growing selection.Ut enim ad minim veniam,</p>
</article>
</div>

2 个答案:

答案 0 :(得分:0)

编辑高度&amp; div的溢出属性不会隐藏屏幕阅读器中的内容。您需要在短文本类中使用display:none。 (另外,在CSS中编写类更简单,只需使用jquery添加/删除类名)。

答案 1 :(得分:0)

几个月前,我的任务是解决在保持WCAG 2.0可访问性的同时实现“阅读更多”/“阅读更少”链接的相同问题。

如果您不反对使用Bootstrap和jQuery,我有一个非常好的解决方案。引导程序collapse使它成为可能。

https://jsfiddle.net/rmatnwrm/