Skip to content

Commit afdb5a8

Browse files
authored
Merge pull request #645 from marp-team/update-morphable-example
Update docs about bespoke transitions: Make simplify the example of morphable elements
2 parents 9f4e15e + 4ccff5c commit afdb5a8

File tree

1 file changed

+33
-44
lines changed

1 file changed

+33
-44
lines changed

docs/bespoke-transitions/README.md

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -518,48 +518,42 @@ If there were multiple pairs defined by `view-transition-name` CSS property with
518518

519519
In this example, the icon image of "1" on every page is marked as morphable elements named "one" by `view-transition-name` CSS property.
520520

521-
Generally setting [`contain` CSS property][contain] as `layout` or `paint` is also required together with `view-transition-name`. If it lacked, the browser may ignore the morph transition with the error `Shared element must contain paint or layout`.
522-
523-
[contain]: https://developer.mozilla.org/en-US/docs/Web/CSS/contain
524-
525521
```markdown
526522
---
527523
theme: gaia
528524
transition: fade
529525
style: |
530-
/* ⬇️ Mark the image of "1" in every pages as morphable image named as "one" ⬇️ */
531-
img[alt="1"] {
532-
view-transition-name: one;
533-
contain: layout; /* required */
534-
}
535-
536-
/* Generic image styling for number icons */
537-
img:is([alt="1"], [alt="2"], [alt="3"]) {
526+
img[title~="step"] {
538527
height: 64px;
539528
position: relative;
540529
top: -0.1em;
541530
vertical-align: middle;
542531
width: 64px;
532+
533+
/* ⬇️ Mark the image of "1" in every pages as morphable image named as "one" ⬇️ */
534+
&[alt="1"] {
535+
view-transition-name: one;
536+
}
543537
}
544538
---
545539

546540
# Today's topics
547541

548-
- ![1](https://icongr.am/material/numeric-1-circle.svg?color=666666) Introduction
549-
- ![2](https://icongr.am/material/numeric-2-circle.svg?color=666666) Features
550-
- ![3](https://icongr.am/material/numeric-3-circle.svg?color=666666) Conclusion
542+
- ![1](https://icongr.am/material/numeric-1-circle.svg?color=666666 'step') Introduction
543+
- ![2](https://icongr.am/material/numeric-2-circle.svg?color=666666 'step') Features
544+
- ![3](https://icongr.am/material/numeric-3-circle.svg?color=666666 'step') Conclusion
551545

552546
---
553547

554548
<!-- _class: lead -->
555549

556-
![1 w:256 h:256](https://icongr.am/material/numeric-1-circle.svg?color=ff9900)
550+
![1 w:256 h:256](https://icongr.am/material/numeric-1-circle.svg?color=ff9900 'step')
557551

558552
# Introduction
559553

560554
---
561555

562-
# ![1](https://icongr.am/material/numeric-1-circle.svg?color=666666) Introduction
556+
# ![1](https://icongr.am/material/numeric-1-circle.svg?color=666666 'step') Introduction
563557

564558
Marp is an open-sourced Markdown presentation ecosystem.
565559

@@ -568,21 +562,16 @@ It provides a writing experience of presentation slides by Markdown.
568562

569563
#### Use HTML to mark morphable contents
570564

571-
By using an inline HTML with enabling raw HTML rendering by `--html` Marp CLI option, you can mark a group of morphable contents with more flexibility.
572-
573-
This example is defining the style of `morph` class, to mark the inner elements as morphable.
565+
This example is defining the style for `data-morph` attribute, to mark the inner elements as morphable.
574566

575567
```markdown
576568
---
577569
header: Bubble sort
578570
transition: fade
579571
style: |
580-
/* Define the style of "morph" class */
581-
.morph {
582-
display: inline-block;
583-
view-transition-name: var(--morph-name);
584-
contain: layout;
585-
vertical-align: top;
572+
/* Define the style of morphable elements (Requires Chrome 133 and later) */
573+
[data-morph] {
574+
view-transition-name: attr(data-morph type(<custom-ident>), none);
586575
}
587576

588577
/* Global style */
@@ -591,40 +580,40 @@ style: |
591580
}
592581
---
593582

594-
<span class="morph" style="--morph-name:b7;">███████</span> 7
595-
<span class="morph" style="--morph-name:b5;">█████</span> 5
596-
<span class="morph" style="--morph-name:b3;">███</span> 3
597-
<span class="morph" style="--morph-name:b9;">█████████</span> 9
583+
<span data-morph="bar7">███████</span> 7
584+
<span data-morph="bar5">█████</span> 5
585+
<span data-morph="bar3">███</span> 3
586+
<span data-morph="bar9">█████████</span> 9
598587

599588
---
600589

601-
<span class="morph" style="--morph-name:b5;">█████</span> 5
602-
<span class="morph" style="--morph-name:b7;">███████</span> 7
603-
<span class="morph" style="--morph-name:b3;">███</span> 3
604-
<span class="morph" style="--morph-name:b9;">█████████</span> 9
590+
<span data-morph="bar5">█████</span> 5
591+
<span data-morph="bar7">███████</span> 7
592+
<span data-morph="bar3">███</span> 3
593+
<span data-morph="bar9">█████████</span> 9
605594

606595
---
607596

608-
<span class="morph" style="--morph-name:b5;">█████</span> 5
609-
<span class="morph" style="--morph-name:b3;">███</span> 3
610-
<span class="morph" style="--morph-name:b7;">███████</span> 7
611-
<span class="morph" style="--morph-name:b9;">█████████</span> 9
597+
<span data-morph="bar5">█████</span> 5
598+
<span data-morph="bar3">███</span> 3
599+
<span data-morph="bar7">███████</span> 7
600+
<span data-morph="bar9">█████████</span> 9
612601

613602
---
614603

615-
<span class="morph" style="--morph-name:b3;">███</span> 3
616-
<span class="morph" style="--morph-name:b5;">█████</span> 5
617-
<span class="morph" style="--morph-name:b7;">███████</span> 7
618-
<span class="morph" style="--morph-name:b9;">█████████</span> 9
604+
<span data-morph="bar3">███</span> 3
605+
<span data-morph="bar5">█████</span> 5
606+
<span data-morph="bar7">███████</span> 7
607+
<span data-morph="bar9">█████████</span> 9
619608
```
620609

621-
The name of group can set through CSS variable in `style` attribute.
610+
The name of morphable elements can set through `data-morph` attribute. Please note that this example is using [advanced `attr()` function](https://developer.chrome.com/blog/advanced-attr), that requires Chrome 133 and later.
622611

623612
<p align="center">
624613
<img src="./images/morphing-animation-2.gif" alt="Use HTML to mark morphable contents" width="480" height="270" />
625614
</p>
626615

627-
Due to the security reason, Marp CLI does not render raw HTML tags in Markdown by default. You have to should add `--html` option to use inline HTMLs.
616+
Due to the security reason, Marp CLI does not render `data-*` attributes in raw `<span>` elements in Markdown by default. You have to should add `--html` option to use.
628617

629618
```bash
630619
marp morphable.md --html

0 commit comments

Comments
 (0)