Skip to content

Instantly share code, notes, and snippets.

@txan2
Created July 19, 2018 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save txan2/11e6237177603b33aece631c3ce04b98 to your computer and use it in GitHub Desktop.
Save txan2/11e6237177603b33aece631c3ce04b98 to your computer and use it in GitHub Desktop.
AMP scrolling
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>amp-bind</title>
<link rel="canonical" href="https://ampbyexample.com/components/amp-bind/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<!-- ## Setup -->
<!--
Import the amp-bind component in the header.
-->
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>
<script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
.redBackground {
background-color: red;
}
.greenBackground {
background-color: green;
}
.yellowBackground {
background-color: yellow;
}
/* make the demo look better */
#amp-bind-sample > * {
padding: 1rem;
}
#amp-bind-sample > * + * {
margin-top: 1rem;
}
.bg-green { background-color: #2ecc40; }
.bg-yellow { background-color: #ffdc00; }
.spacer {
height: 60rem;
width: 100%;
}
</style>
</head>
<body>
<section id="amp-bind-sample">
<amp-state id="remoteAnimals" [src]="remoteAnimalUrl">
<script type="application/json">
{ "currentAnimal" : "dog",
"dog": {
"imageUrl": "/img/Border_Collie.jpg",
"videoUrl": "/video/dog-video.mp4",
"style": "greenBackground",
"iframeUrl": "https://player.vimeo.com/video/183849543"
}
}
</script>
</amp-state>
<!-- ## Load state remotely -->
<!--
By setting the `src` attribute of the `amp-state`,
new data is fetched and merged into the `amp-state`.
-->
<a href="https://example.com/" target="_blank"
on="tap:AMP.setState({remoteAnimalUrl: '/json/amp-bind-data-new-state.json?RANDOM'}),scroll-target.scrollTo()"
>
Set to Bird
</a>
<!-- Similarly to the samples above, you can bind to text, ... -->
<p [text]="'This is a ' + remoteAnimals.currentAnimal + '.'">This is a dog.</p>
<!--
... bind to `amp-img` `src ` ... and all the components described [here](https://www.ampproject.org/docs/reference/components/amp-bind)
-->
<amp-img src="/img/Border_Collie.jpg" layout="responsive" width="300" height="200"
[src]="remoteAnimals[remoteAnimals.currentAnimal].imageUrl">
</amp-img>
</section>
<div class="spacer"></div>
<p id="scroll-target">Scroll target</p>
</body>
</html>
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>amp-bind</title>
<link rel="canonical" href="https://ampbyexample.com/components/amp-bind/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<!-- ## Setup -->
<!--
Import the amp-bind component in the header.
-->
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>
<script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
.redBackground {
background-color: red;
}
.greenBackground {
background-color: green;
}
.yellowBackground {
background-color: yellow;
}
/* make the demo look better */
#amp-bind-sample > * {
padding: 1rem;
}
#amp-bind-sample > * + * {
margin-top: 1rem;
}
.bg-green { background-color: #2ecc40; }
.bg-yellow { background-color: #ffdc00; }
.spacer {
height: 60rem;
width: 100%;
}
</style>
</head>
<body>
<section id="amp-bind-sample">
<amp-state id="remoteAnimals" [src]="remoteAnimalUrl">
<script type="application/json">
{ "currentAnimal" : "dog",
"dog": {
"imageUrl": "/img/Border_Collie.jpg",
"videoUrl": "/video/dog-video.mp4",
"style": "greenBackground",
"iframeUrl": "https://player.vimeo.com/video/183849543"
}
}
</script>
</amp-state>
<!-- ## Load state remotely -->
<!--
By setting the `src` attribute of the `amp-state`,
new data is fetched and merged into the `amp-state`.
-->
<a href="https://example.com/" target="_blank"
on="tap:scroll-target.scrollTo(),AMP.setState({remoteAnimalUrl: '/json/amp-bind-data-new-state.json?RANDOM'})"
>
Set to Bird
</a>
<!-- Similarly to the samples above, you can bind to text, ... -->
<p [text]="'This is a ' + remoteAnimals.currentAnimal + '.'">This is a dog.</p>
<!--
... bind to `amp-img` `src ` ... and all the components described [here](https://www.ampproject.org/docs/reference/components/amp-bind)
-->
<amp-img src="/img/Border_Collie.jpg" layout="responsive" width="300" height="200"
[src]="remoteAnimals[remoteAnimals.currentAnimal].imageUrl">
</amp-img>
</section>
<div class="spacer"></div>
<p id="scroll-target">Scroll target</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment