Skip to content

Commit

Permalink
Write twitter-header sample
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Jan 21, 2016
1 parent bc474ab commit ea82d52
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
_*
Binary file added twitter-header/avatar.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added twitter-header/banner.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions twitter-header/compworklet.js
@@ -0,0 +1,46 @@
/*
Copyright 2016 Google, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
function tick(timestamp) {
var scroll = self.scroller.scrollTop/(189-45);

var t = self.avatar.transform;
if (scroll > 1) {
scroll = 1;
}
t.m11 = 1 - 0.6*scroll;
t.m22 = 1 - 0.6*scroll;
t.m41 = -scroll*45*0.6;
if(self.scroller.scrollTop > 189-45*0.6) {
t.m42 = self.scroller.scrollTop - (189-45*0.6) + 45;
} else {
t.m42 = 45;
}
self.avatar.transform = t;

self.bar.opacity = scroll;
var t = self.bar.transform;
t.m42 = self.scroller.scrollTop;
self.bar.transform = t;

self.requestAnimationFrame(tick);
}

self.onmessage = function(e) {
self.scroller = e.data[0];
self.avatar = e.data[1];
self.bar = e.data[2];
self.requestAnimationFrame(tick);
};
56 changes: 56 additions & 0 deletions twitter-header/index.html
@@ -0,0 +1,56 @@
<!doctype html>
<!--
Copyright 2016 Google, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="scroller">
<section class="bar"></section>
<header>
<picture class="avatar">
<img src="avatar.jpg">
</picture>
<section class="profilecontrols">
<button>Friends</button>
<button>Edit Profile</button>
</section>
</header>
<section class="profile">
Surma
@surma
</section>
<section class="tweets">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. </p>
<p>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. </p>
<p>Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. </p>
<p>Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. </p>
<p>Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. </p>
</section>
<script>
var $ = document.querySelector.bind(document);
var worklet = new CompositorWorker('compworklet.js');
var scrollerProxy = new CompositorProxy($('#scroller'), ['scrollTop', 'transform']);
var avatarProxy = new CompositorProxy($('.avatar'), ['transform']);
var barProxy = new CompositorProxy($('.bar'), ['transform', 'opacity']);
worklet.postMessage([scrollerProxy, avatarProxy, barProxy]);
console.log('hai2');
</script>
</div>
</body>
</html>
93 changes: 93 additions & 0 deletions twitter-header/style.css
@@ -0,0 +1,93 @@
/*
Copyright 2016 Google, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
* {
box-sizing: border-box;
}
html, body {
margin: 0;
border :0;
padding: 0;
width: 100vw;
height: 100vh;
background-color: black;
}
body {
display: flex;
justify-content: center;
align-items: center;
font-family: sans-serif;
}
#scroller {
width: 360px;
height: 567px;
overflow-y: auto;
overflow-x: hidden;
background-color: #black;
color: white;
border: 5px solid rgb(80, 80, 80);
border-radius: 5px;
position: relative;
}
header {
width: 100%;
height: 189px;
padding: 0 5px;
background: url('banner.jpg') 50% 50%/cover;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-end;
}
.avatar {
transform: translate(0, 45px);
z-index: 2;
}
.avatar > img {
width: 90px;
height: 90px;
border: 5px solid white;
border-radius: 15px;
}
.profilecontrols {
transform: translate(0, 45px);
display: flex;
flex-direction: row;
justify-content: flex-end;
}
.profilecontrols > button {
height: 40px;
margin-left: 5px;
border: 1px solid rgba(255, 255, 255, 0.27);
color: white;
background-color: transparent;
border-radius: 5px;
}
.profile {
margin-top: 45px;
padding: 10px;
}
.tweets {
padding: 10px;
}
.bar {
opacity: 0;
position: absolute;
top: 0;
width: 100%;
height: 50px;
z-index: 1;
background-color: rgba(255, 255, 255, 0.74);
}

0 comments on commit ea82d52

Please sign in to comment.