Examples
You can try Birdview on various pages from this website:
- Homepage: see all website's content in one glance
- 3D visualization: browse a gallery of 3D renderings
- Blog: notes about technology & art
- Making of the plane, the canyon & the clouds: long form article with text and figures
- Birdviews of the web: birdviews of various websites
Usage
1. Setup
Include birdview.js
and birdview.css
in your HTML file:
<link rel="stylesheet" type="text/css" href="birdview.css"/>
<script type="text/javascript" src="birdview.js"></script>
2. Start
Enable Birdview by calling the initialization method:
birdview.init();
3. Control
You can trigger Birdview by pressing the Z key or with a pinch-in gesture on a touch device.
You can also trigger Birdview by clicking any HTML element with a birdview_toggle
class:
<button class="birdview_toggle">Birdview</button>
Or you can toggle Birdview programmatically using the toggle method:
birdview.toggle();
4. Stop
You can stop Birdview from running on your page by calling:
birdview.destroy();
The destruction method is called inside the initialization method. Calling birdview.init()
multiple times shouldn't create any undesirable overlapping.
Options
You can modify Birdview's default settings by passing a configuration object to the initialization method:
birdview.init({
shortcut: 90,
button: true,
button_text: 'Birdview',
speed: 0.3,
easing: 'ease',
overlay: true,
origin_X: 50,
callback_start: function(){},
callback_end: function(){}
});
1. User interface
-
shortcut
: Number
Keyboard keyCode. Default value is 90 for 'Z'. -
button
: Boolean
Creates a button on the page to toggle Birdview. Default value is true. The default CSS puts the button in the upper right corner of the screen withposition: absolute
. You can style the button inbirdview.css
with the IDbirdview_auto_generated_button
, or you can disable it and set your own button with a class ofbirdview_toggle
.
-
button_text
: String
Text inside Birdview’s auto generated button. Default value is 'Birdview'. -
overlay
: Boolean
Shows a UI overlay when Birdview is active. Default value is true. Disabling the overlay allows direct action on click areas in Birdview mode. That's both handy—zoomable UI—and problematic—tiny click areas. You can style the overlay inbirdview.css
with the IDbirdview_auto_generated_overlay
.
2. Effects
-
speed
: Number
Transition speed, in seconds. Default value is 0.3.
-
easing
: String
Animation timing function. Default value is 'ease'. See easings.net for a gallery of easing functions.
-
origin_X
: Number
Transformation origin on the X axis, in percentage. Default value is 50. Set to the appropriate value on documents that are not horizontally centered.
3. Callbacks
-
callback_start
: Function
Calls a function when you enter Birdview. -
callback_end
: Function
Calls a function when you exit Birdview.
Here's how you can use callback functions:
function fly(){
console.log('taking off');
}
function land(){
console.log('landing');
}
birdview.init({
callback_start: fly,
callback_end: land
});
Example: when you are in Birdview, you can emphasize your headings while fading out everything else.
How it works
Birdview.js wraps all body
HTML content inside a custom DOM structure: everything is put inside an inner div birdview_child
, itself wrapped inside an outer div birdview_parent
:
<body>
<div id="birdview_parent">
<div id="birdview_child">
<!-- Original HTML -->
</div>
</div>
</body>
The birdview effect is performed using CSS scale transforms on the birdview_child
div. To ensure a continuous transition between the current scrolling position and the birdview, the Y origin of the scale transform must be at the vertical midpoint of the viewport.
The vertical midpoint of the viewport is then projected into the document, and a CSS scale transform is applied to the birdview_child
using the projected origin. But if we stop there, the birdview wouldn't necessarily fit inside the viewport: some of the scaled document would be hidden below or above the viewport, depending on your scrolling position, precisely because the vertical midpoint of the viewport isn't necessarily the vertical midpoint of the document—with the notable exception of when you are exactly halfway through the document!
To compensate for that shift, we must apply a vertical translation that is dependent on your scrolling position. That translation is applied to the birdview_parent
div.
Finally, user interface elements such as the optional overlay and button are appended directly to the body
, outside the birdview_parent
, so they are not subject to transformations.
This DOM structure has one consequence for the developer: if your own code creates HTML elements programmatically and appends them to the body
element, then the call order of birdview.init()
matters. If you wish to not include programmatic HTML elements in the birdview, please execute your code after you initialize birdview.js.
Change log
-
Core:
{passive: false}
event listeners are back. They are required for pinch gestures to work on Mobile Safari.
UI: Birdview button is now enabled by default.
CSS: Changed default ID for the Birdview button and overlay. - UI: added a setting to customize the text of the Birdview button.
-
Core: removed
{passive: false}
from touch events listeners.{passive: false}
event listeners make custom pinch gestures easier to perform on Chrome for Android (see Scrolling intervention), but they also make Birdview interfere with the native zoom. - Core: removed the option to show custom messages on screen for mobile debugging. That option has spun off and became a separate plugin: Showlog.js.
- Core: focused elements are preserved after Birdview’s initialization.
- UI: fixed the breadcrumb navigation URLs of the Birdview overlay.
- UI: if the page already fits into the viewport, Birdview plays a bounce animation. Requires support for Web Animations API.
-
Core: elements with
position:fixed
no longer lose their fixed positioning after calling Birdview. See blog post Position fixed and CSS transforms. - API: improved and documented logging on touch devices.
-
CSS: additional reset styles in
birdview.css
for uniformity across web pages. -
UI: the keyboard shortcut was disabled if any
input
element was in focus. Now onlyinput
elements of typetext
disable the keyboard shortcut. -
CSS: additional reset styles in
birdview.css
for uniformity across web pages. - API: simplified settings names.
-
CSS: simplified the default font stack in
birdview.css
, and added:active
and:focus
states to all clickable elements. - Accessibility: added focus priority to the Birdview overlay when Birdview is active.
Known issues
- Birdview tries its best to not interfere with pinch to zoom on touch devices. A pinch triggers Birdview only if the page is at 1:1 scale. If the user zooms in, then the page is no longer at 1:1 and a pinch would bring the page back to 1:1 without triggering Birdview. This works well on Mobile Safari and Firefox for Android, but not on Chrome for Android. I did not find a way to detect a user-initiated page zoom on Chrome for Android. Therefore, if the user pinches out to zoom then pinches back in, it will will trigger Birdview instead of getting the page back to 1:1. In order to get back to the initial scale, the user must pinch out some more then, without lifting the fingers, pinch in until the page is at 1:1 scale.
- Resizing the browser window in Birdview mode can reposition the birdview improperly.
- Birdview.js doesn't play well with documents where the body content has
overflow:hidden
. - Vertical margins on the top most or bottom most element of a page mess with Birdview's page height measurement.
Birdview.js is tested on:
- Desktop: Google Chrome, Mozilla Firefox, and Microsoft Edge on Windows 10.
- Mobile: Mobile Safari, Chrome and Firefox for Android.
Links
- Birdview Chrome extension (outdated): Kudos to Jess Telford for making a Google Chrome browser extension.
- Birdview early prototype: Early Birdview prototype back from February 2012! The idea was that when you land on a webpage, you scroll through an overview of the document before diving in.
- Joni Korpi: Joni Korpi zoomable UI website. His experiment was one motivation to finish work on Birdview.
- Anatomy of a Javascript plugin: very good reference by @ChrisFerdinandi on how to structure a Javascript plugin.
License
Birdview.js is published under the GNU General Public License.