javascript - 如果旋转元素的高度增加了某个值,那么旋转元素的真实位置(顶部,左侧)是什么?
问题描述
我有一个以特定角度旋转的 div。如果我要将 div 的高度增加一些值。如何获取或计算当前div的真正上左值和高度同时增加后div的真正上左值。我想计算这些值以在高度增加后保留原始的真实右下角位置
JS Fiddle描述了我要解决的问题
const increaseHeight = function(div){
/*
calculate the true top and left of the div
calculate the true top and left of the div after the height is increased
calculate the difference that needs to be applied such that when the height changes the original true bottom right position remains the same after the height is increased
*/
}
请注意,我只想使用 javascript 来解决这个问题,并且没有应用额外的 css
解决方案
您可以使用它getBoundingClientRect()
来检索已转换元素的属性:
var x = document.getElementById("app");
console.log(x.getBoundingClientRect());
你的小提琴应该记录:
DOMRect {x: 17.10739517211914, y: 47.10739517211914, width: 265.78521728515625, height: 265.78521728515625, top: 47.10739517211914, …}
推荐阅读
- css - 动态反应去除空间
- google-cloud-platform - GCP 内部 http(s) 负载平衡器在 300 秒后超时
- python - 熊猫,我想取另一个表的列,并且对于该列的每个值,每个月在另一个表中跟踪它
- python - VSCode绿色运行按钮的键绑定?
- r - 有没有一种简单的方法可以将列表转换为 R 中的列数据框?
- sql - 使用 Spool SQLPLUS 自定义文件格式
- sql - 计划 Firestore
- mysql - 在sql中比较同一张表中的数据
- c - 输入不会进入 while -loop
- elasticsearch - 具有余弦相似度运行时错误的弹性搜索查询?