Это из MDN:
Свойство Element.scrollTop
получает или задает количество пикселей, при котором содержимое элемента прокручивается по вертикали.
Свойство Element.scrollHeight
только для чтения являетсяизмерение высоты содержимого элемента, включая содержимое, не видимое на экране из-за переполнения.
Свойство Element.clientHeight
только для чтения равно нулю для элементов без CSS или встроенных блоков макета;в противном случае это внутренняя высота элемента в пикселях.Он включает отступы, но исключает границы, поля и горизонтальные полосы прокрутки (если есть).
Я использую все эти свойства, чтобы вычислить dashoffset
пути, чтобы анимация заканчивалась при завершении прокрутки.
Надеюсь, это то, что вам нужно.
// Get the id of the <path> element and the length of <path>
var triangle = document.getElementById("triangle");
var length = triangle.getTotalLength();
var dasharray = length;
var dashoffset = length;
// The start position of the drawing
triangle.style.strokeDasharray = dasharray;
// Hide the triangle by offsetting dash. Remove this line to show the triangle before scroll draw
triangle.style.strokeDashoffset = dashoffset;
scrollingContent.addEventListener(
"scroll",
function(e) {
dashoffset =
length -
e.target.scrollTop /
((e.target.scrollHeight - scrollingContent.clientHeight) / length);
triangle.style.strokeDashoffset = dashoffset;
},
false
);
#mySVG {
position: fixed;
top: 5%;
width: 400px;
height: 210px;
margin-left: 10%;
border:1px solid;
background:rgba(255,255,255,.85);
pointer-events:none;
}
#scrollingContent{display:block;width:20em; max-height:100vh; overflow:scroll}
<svg id="mySVG">
<path fill="none" stroke="red" stroke-width="3" id="triangle" d="M75 20 L75 200 L160 200" />
Sorry, your browser does not support inline SVG.
</svg>
<p id="scrollingContent">
I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:-0
I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:-0
I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:-0
I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:I want that whenever a user scrolls my web page, "Live in Bliss" should be drawn. I have managed to draw L, but am not sure how can I go with other elements. I tried using multiple svgs, but it wasn't giving the desired output. Following is my code:-
</p>