2017-07-07 57 views
-1

我正在做一些可訪問性(ADA)的任務,團隊要求我只在選項卡上設置一個可視指針,而不是點擊。眼下如何僅在選項卡上設置元素的輪廓而不是單擊?

enter image description here

我可以看到淡藍色的外框當我點擊的錨,也當我標籤他們。 我需要該輪廓才能在選項卡上顯示。

有什麼建議嗎?

+2

「有什麼建議?」花更多時間研究可訪問性並瞭解焦點如何工作。點擊一個可聚焦的元素將其聚焦。 Tab也改變了焦點。不要刪除重點指標點擊,修復焦點指標更加有吸引力,同時仍然可以訪問。 – zzzzBov

+1

@zzzzBov我認爲OP理解焦點是如何工作的。你否認問題,不提供解決方案。 –

+0

@VadimOvchinnikov,對我來說,這個問題顯然是一個[XY問題](https://meta.stackexchange.com/q/66377/153542)。至於「不提供解決方案」,你是對的,這就是我留下評論的原因。如果*您*想提供解決方案,您絕對可以自由發佈自己的答案。 – zzzzBov

回答

1

你只需要在click活動中刪除的輪廓,並在focus事件設置輪廓。

var elements = Array.from(document.querySelectorAll("a")); 
 

 
elements.forEach(a => a.addEventListener("click", function() { 
 
    a.classList.add("no-outline"); 
 
})); 
 

 
elements.forEach(a => a.addEventListener("focus", function() { 
 
    a.classList.remove("no-outline"); 
 
}));
.no-outline { 
 
    outline: 0; 
 
}
Some text. <a href="#">This is link</a>. 
 
Also we have <a href="#">another link</a>

0

所以這將處理點擊或tabkey事件。它們以不同的方式顯示,但是兩者都調用相同的功能。希望能幫助到你!

/********* 
 
* function that simply toggles the pane. 
 
* doesn't care what calls it, simply that 
 
* it gets the proper data. We can call it 
 
* in the click handler (as in the HTML) or 
 
* in the keyup handler (as below). 
 
* either has the same functionality, but 
 
* can have their own processing. 
 
*********/ 
 
openCity = function openCity(evt, cityName) { 
 
    // Declare all variables 
 
    var i, tabcontent, tablinks; 
 

 
    // Get all elements with class="tabcontent" and hide them 
 
    tabcontent = document.getElementsByClassName("tabcontent"); 
 
    for (i = 0; i < tabcontent.length; i++) { 
 
    tabcontent[i].style.display = "none"; 
 
    } 
 

 
    // Get all elements with class="tablinks" and remove the class "active" 
 
    tablinks = document.getElementsByClassName("tablinks"); 
 
    for (i = 0; i < tablinks.length; i++) { 
 
    tablinks[i].className = tablinks[i].className.replace(" active", ""); 
 
    } 
 

 
    // Show the current tab, and add an "active" class to the button that opened the tab 
 
    document.getElementById(cityName).style.display = "block"; 
 
    evt.currentTarget.className += " active"; 
 
} 
 

 
/******** 
 
* Handler for the tab key functionality. 
 
* Processes separately from the click 
 
* function, as is shown by the different 
 
* coloring. However, either click or tab 
 
* key can trigger the same tab display 
 
* function. 
 
*********/ 
 

 
var tabIndex; 
 
var tabEls = $(".tab button"); 
 
$(document).ready(function() { 
 
    $(document).on("keyup", function(evt) { 
 
    // Prevent the tab key from propagating 
 
    evt.preventDefault(); 
 
    evt.stopPropagation(); 
 

 
    // tab has been pressed 
 
    if (evt.which == 9) { 
 
     // Currently, no tab has been chosen, so we select the first 
 
     if ($(".tabbedActive").length == 0) { 
 
     tabEls.eq(0).addClass("tabbedActive"); 
 
     } else { 
 
     // we have a selected tab. So we either choose the next, or 
 
     // the first if we need to rotate through. 
 
     tabIndex = tabEls.parent().find('.tabbedActive').index(); 
 

 
     // Remove the class from all tab els 
 
     tabEls.removeClass('tabbedActive'); 
 
     if (tabIndex == tabEls.length - 1) { 
 
      tabEls.eq(0).addClass("tabbedActive"); 
 
     } else { 
 
      tabEls.eq(tabIndex + 1).addClass("tabbedActive"); 
 
     } 
 
     } 
 
     
 
     // Now that we have a selected tab, use that to toggle the pane 
 
     openCity(evt, tabEls.parent().find('.tabbedActive').text()) 
 

 
    } 
 
    }) 
 
});
a 
 
/* Style the tab */ 
 

 
div.tab { 
 
    overflow: hidden; 
 
    border: 1px solid #ccc; 
 
} 
 

 

 
/* Style the buttons inside the tab */ 
 

 
div.tab button { 
 
    float: left; 
 
    border: none; 
 
    outline: none; 
 
    cursor: pointer; 
 
    padding: 14px 16px; 
 
    transition: 0.3s; 
 
} 
 

 

 
/* Change background color of buttons on hover */ 
 

 
div.tab button:hover { 
 
    background-color: #ddd; 
 
} 
 

 

 
/* Create an active/current tablink class */ 
 

 
div.tab button.active { 
 
    background-color: #ccc; 
 
} 
 

 
.tabbedActive { 
 
    border: 1px solid yellow; 
 
    background-color: #cc0; 
 
} 
 

 

 
/* Style the tab content */ 
 

 
.tabcontent { 
 
    display: none; 
 
    padding: 6px 12px; 
 
    border: 1px solid #ccc; 
 
    border-top: none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="tab"> 
 
    <button class="tablinks" onclick="openCity(event, 'London')">London</button> 
 
    <button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button> 
 
    <button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button> 
 
</div> 
 

 
<div id="London" class="tabcontent"> 
 
    <h3>London</h3> 
 
    <p>London is the capital city of England.</p> 
 
</div> 
 

 
<div id="Paris" class="tabcontent"> 
 
    <h3>Paris</h3> 
 
    <p>Paris is the capital of France.</p> 
 
</div> 
 

 
<div id="Tokyo" class="tabcontent"> 
 
    <h3>Tokyo</h3> 
 
    <p>Tokyo is the capital of Japan.</p> 
 
</div>

相關問題