mirror of https://github.com/sveltejs/svelte
parent
b4c2226438
commit
0c8cb44d01
@ -0,0 +1,31 @@
|
|||||||
|
export default {
|
||||||
|
skip_if_ssr: true,
|
||||||
|
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
assert.equal(window.pageYOffset, 0);
|
||||||
|
|
||||||
|
const event = new window.Event('scroll');
|
||||||
|
Object.defineProperties(window, {
|
||||||
|
pageYOffset: {
|
||||||
|
value: 234,
|
||||||
|
configurable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await window.dispatchEvent(event);
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<p style="position: fixed; top: 1em; left: 1em;">scroll\ny\nis\n234.\n234\n*\n234\n=\n54756</p><div style="height: 9999px;"></div>`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
after_test() {
|
||||||
|
Object.defineProperties(window, {
|
||||||
|
pageYOffset: {
|
||||||
|
value: 0,
|
||||||
|
configurable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
import { writable, derived } from 'svelte/store';
|
||||||
|
const y = writable(0);
|
||||||
|
const y_squared = derived(y, $y => $y * $y);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window bind:scrollY={$y}/>
|
||||||
|
|
||||||
|
<p style="position: fixed; top: 1em; left: 1em;">
|
||||||
|
scroll y is {$y}. {$y} * {$y} = {$y_squared}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div style="height: 9999px">
|
||||||
|
|
||||||
|
</div>
|
Loading…
Reference in new issue