LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Sunday, May 12, 2019

指定した要素の左上からの位置を取得したい(getBoundingClientRect)


top, left, right, bottomを取得してアラートに出してみる



コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
<body>

<textarea id="ta"></textarea>

<script>
getDomRect();
function getDomRect() {
  var element = document.getElementById('ta');
  var domRect = element.getBoundingClientRect();
  var top = domRect.top;
  var left = domRect.left;
  var right = domRect.right;
  var bottom = domRect.bottom;
  alert([top, left, right, bottom]);
}

</script>
</body>
</html>


参考

Element​.get​Bounding​Client​Rect()

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...