javascript - 在 View 中显示 SVG 动画

标签 javascript jquery css svg

<分区>

我只想在 SVG 处于 View 中时显示动画 CSS,当我滚动回到该元素时,它会重新开始。我找到了一个演示并尝试放入我的 SVG 元素,但没有用。请帮帮我!谢谢!

Activate CSS3 animation when the content scrolls into view

我的 HTML

<div class="lineNone">
        <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 614 53" style="enable-background:new 0 0 614 53; width: 70%; margin-top: 40px;" xml:space="preserve">

    <polyline class="st0 eighty" points="0.5,53 0.5,20.7 613.5,20.7 613.5,53 "/><line class="st1" x1="307" y1="53" x2="307" y2="0"/></svg>
</div>

最佳答案

这是你能做的,

<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.2.1.js"></script>
    <script>
        $(window).scroll(function () {
        var s = $(window).scrollTop(),
                d = $(document).height(),
                c = $(window).height();
                scrollPercent = (s / (d-c)) * 100;
                var position = scrollPercent;

        $("#progressbar").attr('value', position);

        });
    </script>
    <style>
        progress {
            position:fixed;
            top:15px;
        }
    </style>
</head>
<body>
    <progress id="progressbar" value="0" max="100"></progress>

    <img src="https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/accessible.svg">
    <div id="horizontal">test</div>
</body>

关于javascript - 在 View 中显示 SVG 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47809297/

上一篇:css - DSpace 6.2 文档项 View 自定义

下一篇:javascript - 在不滚动的情况下调用滚动窗口

相关文章:

css - sass @include 以不同的方式工作

javascript - 如何使用 HTML 和 CSS 模拟从图像/div 到另一个图像/div 的光线

javascript - 选择选项后触发 'click'?

php - IE 所需的 CSS/Javascript 下拉导航修复

javascript - Jquery/javascript 检查 div 是否完成加载?

javascript - 没有缩略图的 Fancybox 画廊

javascript - Jquery Slidein 滑出悬停效果问题

javascript - 在 D3 中放大和缩小时如何更改平移和缩放的速度(使用 zoom.on 和 d3.event.translate,d3.event.zoom)?

javascript - 如何为对象的所有实例调用对象函数

html - 旋转的 div 导致 Internet Explorer 中的水平滚动条