Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions demo/scroll-timeline-external-css/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<script src="../../dist/scroll-timeline.js"></script>

<link rel="stylesheet" href="styles.css">
<body>
<div id=container>
<div id=progress></div>
<div class="spacer"></div>
<div class="spacer"></div>
<div class="spacer"></div>
</div>
</body>

33 changes: 33 additions & 0 deletions demo/scroll-timeline-external-css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#container {
scroll-timeline-name: --foo, --bar;
overflow: scroll;
width: 500px;
height: 500px;
border: 1px solid #333;
}

.spacer {
width: 100%;
height: 500px;
}

#progress {
position: fixed;
height: 10px;
background-color: red;
animation: 1s progress linear forwards;
animation-timeline: --foo;
}

body {
margin: 0px;
}

@keyframes progress {
from {
width: 0px;
}
to {
width: 500px;
}
}
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<li>
<a href="demo/view-timeline-external-css/">demo/view-timeline-external-css</a>
</li>
<li>
<a href="demo/scroll-timeline-external-css/">demo/scroll-timeline-external-css</a>
</li>
<li>
<a href="demo/basic/anonymous-scroll-timeline.html">demo/basic/anonymous-scroll-timeline.html</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion src/scroll-timeline-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,23 @@ function initMutationObserver() {
// Most likely we won't be able to fetch resources from other origins.
return;
}
fetch(linkElement.getAttribute('href')).then(async (response) => {

// Stop loading the stylesheet to ensure that we finished parsing it before it's
// loaded by the browser (and that animations are only started after
// we collected the required options)
const href = linkElement.getAttribute('href')
linkElement.removeAttribute('href')

fetch(href).then(async (response) => {
const result = await response.text();
let newSrc = parser.transpileStyleSheet(result, true);
newSrc = parser.transpileStyleSheet(result, false);
if (newSrc != result) {
const blob = new Blob([newSrc], { type: 'text/css' });
const url = URL.createObjectURL(blob);
linkElement.setAttribute('href', url);
} else {
linkElement.setAttribute('href', href);
}
});
}
Expand Down