简体   繁体   English

IntroJs 提示如果父不可见

[英]IntroJs Hints if parent not Visible

IntroJs hints How can I skip or hide when a parent element is not visible? IntroJs 提示如何在父元素不可见时跳过或隐藏? For some reason only inline seems to be working for my hints.I have the data-hints in spans on the HTML and I need to check if the nearest element is visible or parent/child element.出于某种原因,似乎只有内联对我的提示有效。我在 HTML 的跨度中有数据提示,我需要检查最近的元素是否可见或父/子元素。

var hints = false;

var all = document.getElementsByTagName("*"); var all = document.getElementsByTagName("*");

function introFunction() {函数介绍函数(){

for (var i = 0, max = all.length; i < max; i++) {
    if ((isHidden(all[i]) && hints));
    document.getElementById("#helpFunc").html("Show Help");
    introJs().hideHints();
} else {
    document.getElementById("#helpFunc").html("Hide Help");
    introJs().showHints();
}
hints = !hints;

function isHidden(el) {
    var style = window.getComputedStyle(el);
    return ((style.display === 'none') || (style.visibility === 'hidden'));
}

} }

Instead of trying to get the computed style of the element, try checking the element bounding rectangles - if there aren't any, it means the element is not visible.不要尝试获取元素的计算样式,而是尝试检查元素边界矩形 - 如果没有,则意味着该元素不可见。

!!el.getClientRects().length; // false means el or its parent(s) is hidden

LE: that doesn't work for "visibility: hidden;" LE:这不适用于“可见性:隐藏;” though.尽管。 So maybe you can combine the above with what you already have.因此,也许您可​​以将上述内容与您已有的内容结合起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM