gpt4 book ai didi

javascript - 计算缩放和旋转元素的原始高度

转载 作者:行者123 更新时间:2023-11-28 05:22:26 28 4
gpt4 key购买 nike

在下面的示例中,我有五个部分和一个打印出当前滚动位置、部分高度以及部分在文档中的位置的控制台日志。当部分没有被操作时,在我的屏幕上,结果如下。

Current Scroll Position: 0, Position Of Section: 10, Height Of Section: 196.796875
Current Scroll Position: 0, Position Of Section: 216.796875, Height Of Section: 196.796875
Current Scroll Position: 0, Position Of Section: 423.59375, Height Of Section: 196.796875
Current Scroll Position: 0, Position Of Section: 630.390625, Height Of Section: 196.796875
Current Scroll Position: 0, Position Of Section: 837.1875, Height Of Section: 196.796875

但是,在对部分进行操作后,读取结果。

Current Scroll Position: 0, Position Of Section: 10, Height Of Section: 225.51136779785156
Current Scroll Position: 0, Position Of Section: 216.85635375976562, Height Of Section: 225.51138305664062
Current Scroll Position: 0, Position Of Section: 423.59375, Height Of Section: 225.5113525390625
Current Scroll Position: 0, Position Of Section: 630.4501342773438, Height Of Section: 225.5113525390625
Current Scroll Position: 0, Position Of Section: 837.1875, Height Of Section: 225.5113525390625

我的问题:有没有办法在操作元素之前和操作元素之后获取元素的高度?

查看此 JSFiddle对于未经处理的部分和这个 JSFiddle对于被操纵的。

最佳答案

Dan,你可以尝试为矩形的每个高度设置一个 cookie:

在JS中设置Cookie:

function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}

然后,您可以检索旋转后的高度值:

在 JS 中获取 Cookie:

function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length,c.length);
}
}
return "";
}

这是一种方法。希望这对您有所帮助!

关于javascript - 计算缩放和旋转元素的原始高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38961828/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com