javascript - 是否有可能知道在 Javascript/jQuery 中呈现的 HTML 的垂直维度?

标签 javascript jquery html css mathml

我在一个有很多 MathML 的网站上工作正如您从 examples 中看到的那样,如果不首先渲染代码,则渲染公式的垂直维度很难根据代码猜测。

an example of a rendered formula

 <math display="block"> <mrow> <msub> <mi>a</mi> <mn>0</mn> </msub> 
 <mo>+</mo> <mfrac><mn>1</mn> <mstyle scriptlevel="0" displaystyle="true"> ...

另一方面,在构建页面的过程中,浏览器似乎在某个时刻清楚地“知道”垂直维度。

有没有办法让我在 Javascript/jQuery 中获取有关呈现 HTML 表达式大小的信息,以便我可以相应地调整任何包含框的尺寸?

再多解释一下,如果我正在渲染“纯文本”,我可以通过计算“行”的数量来估计垂直尺寸——但显然这是 hacky 并且对于我感兴趣的情况毫无用处。

jQuery(this).find('span').each( function(){
    if ($(this).css('display') != 'none'){
    // count the number of lines in this span
      num_lines += Math.ceil(jQuery(this).text().length/84);
      max_lines = Math.max(max_lines,num_lines);
    }
}

最佳答案

您可以使用 javascript 函数:

1.innerWidth 属性设置或返回窗口内容区域的内部宽度。

window.innnerHeight 

2.innerHeight 属性设置或返回窗口内容区域的内部高度。

window.innerWidth

关于javascript - 是否有可能知道在 Javascript/jQuery 中呈现的 HTML 的垂直维度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18672782/

相关文章:

javascript - Jquery滚动到不滚动

javascript - getElementsByClassName 是否保持排序?

javascript - jQuery 的 remove() 绕过 FX 队列?我如何只在链的末端使用它?

javascript - 如何使用 javascript 将这个月和下个月添加到 <select> 列表中?

javascript - 如何在我的 iframe 加载时向我的页面添加加载指示器?

javascript - Blogspot 的 HTML/CSS/JS(可能)问题

javascript - ng-hide 元素下的 GIF

javascript - 使用markercluster对多个图层进行聚类

javascript - 内联元素的边框

javascript - 修改应用程序在后台时不调用 FCM/onMessageReceived 的通知