Skip to content

Commit 9b2d153

Browse files
author
Rich Harris
committed
tidy up
1 parent 08b28b4 commit 9b2d153

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

content/tutorial/03-advanced-svelte/09-special-elements/06-svelte-body/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ title: <svelte:body>
44

55
Similar to `<svelte:window>`, the `<svelte:body>` element allows you to listen for events that fire on `document.body`. This is useful with the `mouseenter` and `mouseleave` events, which don't fire on `window`.
66

7-
Add the `mouseenter` and `mouseleave` handlers to the `<svelte:body>` tag:
7+
Add these `mouseenter` and `mouseleave` handlers to the `<svelte:body>` tag...
88

99
```svelte
1010
/// file: App.svelte
1111
<svelte:body
12-
on:mouseenter={handleMouseenter}
13-
on:mouseleave={handleMouseleave}
12+
+++on:mouseenter={() => hereKitty = true}+++
13+
+++on:mouseleave={() => hereKitty = false}+++
1414
/>
1515
```
16+
17+
...and hover over the `<body>`.

content/tutorial/03-advanced-svelte/09-special-elements/06-svelte-body/app-a/src/lib/App.svelte

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<script>
2-
let hereKitty = false;
2+
import kitten from './kitten.png';
33
4-
const handleMouseenter = () =>
5-
(hereKitty = true);
6-
const handleMouseleave = () =>
7-
(hereKitty = false);
4+
let hereKitty = false;
85
</script>
96

107
<svelte:body />
@@ -13,15 +10,15 @@
1310
<img
1411
class:curious={hereKitty}
1512
alt="Kitten wants to know what's going on"
16-
src="/kitten.png"
13+
src={kitten}
1714
/>
1815

1916
<style>
2017
img {
2118
position: absolute;
2219
left: 0;
2320
bottom: -60px;
24-
transform: translate(-80%, 0) rotate(-30deg);
21+
transform: translate(-80%, 0) rotate(-15deg);
2522
transform-origin: 100% 100%;
2623
transition: transform 0.4s;
2724
}

content/tutorial/03-advanced-svelte/09-special-elements/06-svelte-body/app-b/src/lib/App.svelte

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
<script>
2-
let hereKitty = false;
2+
import kitten from './kitten.png';
33
4-
const handleMouseenter = () =>
5-
(hereKitty = true);
6-
const handleMouseleave = () =>
7-
(hereKitty = false);
4+
let hereKitty = false;
85
</script>
96

107
<svelte:body
11-
on:mouseenter={handleMouseenter}
12-
on:mouseleave={handleMouseleave} />
8+
on:mouseenter={() => hereKitty = true}
9+
on:mouseleave={() => hereKitty = false}
10+
/>
1311

1412
<!-- creative commons BY-NC http://www.pngall.com/kitten-png/download/7247 -->
1513
<img
1614
class:curious={hereKitty}
1715
alt="Kitten wants to know what's going on"
18-
src="/kitten.png"
16+
src={kitten}
1917
/>
2018

2119
<style>
2220
img {
2321
position: absolute;
2422
left: 0;
2523
bottom: -60px;
26-
transform: translate(-80%, 0) rotate(-30deg);
24+
transform: translate(-80%, 0) rotate(-15deg);
2725
transform-origin: 100% 100%;
2826
transition: transform 0.4s;
2927
}

0 commit comments

Comments
 (0)