Categories
HTML/CSS Javascript Polymer/Webcomponents

position:fixed and translate3d

Actually, I thought I understood position:fixed in HTML/CSS, but then I had some trouble in combination with transform:translate3d.  Generally position:fixed of an element means, you will have this element relative to the viewport (the browser window) fixed positioned, regardless any scroll-position.

For example the following HTML-Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<div style="position:absolute; left: 20px; top: 20px; width: 150px;  background-color: #7FDBFF">
<h1>positioned Box</h1>
<p>
Lorem ipsum ...
</p>
<div style="position:fixed; background-color:#FF851B; left: 50px; top:50px;width:100px;height: 30px;">
Fixed Box
</div>
</div>
<div style="position:absolute; left: 250px; top: 20px; width: 150px;  background-color: #2ECC40">
<h1>translated Box</h1>
<p>
Lorem ipsum...</p>
<div style="position:fixed; background-color:#FF4136; left: 50px; top:90px;width:100px;height: 30px;">
Fixed Box
</div>
</div>

You will see two absolute positioned boxes (an aqua and a green one) and two fixed boxes (orange and red), which are children of the absolute positioned boxes.

boxes1

The CSS-transform API gives now the possibility to use translate3d as a fast left/top replacement. So we can rewrite the green box to:

1
2
3
4
5
6
7
8
<div style="position:absolute; transform: translate3d(250px, 20px, 0px); width: 150px;  background-color: #2ECC40">
<h1>translated Box</h1>
<p>
Lorem ipsum...</p>
<div style="position:fixed; background-color:#FF4136; left: 50px; top:90px;width:100px;height: 30px;">
Fixed Box
</div>
</div>

We would expect the same result, but got a different one:

boxes2

You see that the red box is jumped to the right. The reason for this result is due to the fact, that translate3d moves the virtual viewport and so the root of the fixed position-relation. Unfortunately the common function getClientBoundingRect, which gives you the rectangle in the viewport, did not respect the translate3d transformation, so that common elements like Polymers iron-dropdown did not work properly anymore.

Until now I have no common solution for that problem, comments are welcome!

You can see, and play around, with my example on JSFiddle.

And also the polymer example shows the problem.

Categories
GWT Polymer/Webcomponents

Resources for Quickstart with GWT and Polymer

Today I would like to give some resources for a quick start in development with GWT and Polymer components. Polymer components are an implementation of basic components with the Webcomponents technology.

  1. The first point is an overview of the Polymer components in GWT. So you have an overview what is possible. You can click through the show case of the gwt-polymer-elements library.
  2. The second point is the official documentation from the GWT-Project. This is a good start to see how you will consume webcomponents with GWT.
  3. As described there you will use the gwt-polymer-elements library from vaadin. This library provides standard polymer (paper and iron elements and some vaadin elements) ready for use with GWT. Currently the Version 1.2.3.0 is the latest release and you will need to use the 2.8.0-SNAPSHOT version of the GWT project.

With these resources and the provided demos you will be able to start your development and play a little bit with the technologies. In the next days I will write some more Howtos about concerning points. If you have some problems with the setup, feel free to write a comment.