【问题标题】:javascript get responsive div height for svg animationjavascript获取svg动画的响应div高度
【发布时间】:2018-04-22 17:10:06
【问题描述】:

我发现了一些创建动画 svg 页面背景的 JS。我只想在 class="workout" 的响应式 DIV 中使用它。我只是在学习 JS,我不知道如何更改此代码以获取 svg 所在的 DIV 的高度。由于 DIV 是全屏宽度,我只需要获取高度。下面是相关代码:

    var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
    svg.setAttribute('width',window.innerWidth);
    svg.setAttribute('height',window.innerHeight);
    document.querySelector('.workout').appendChild(svg);

【问题讨论】:

  • document.getElementsByClassName('workout')[0].clientHeight; ?

标签: javascript svg background


【解决方案1】:

谢谢你,乔治!这帮助我弄清楚该怎么做。这是有效的代码:

    var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
    var divHeight = document.getElementsByClassName('workout')[0].clientHeight;
    svg.setAttribute('width',window.innerWidth);
    svg.setAttribute('height',document.divHeight);
    document.querySelector('.workout').appendChild(svg);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    相关资源
    最近更新 更多