Fixed Elements and Scrolling Divs in iOS 5
I’ve been playing around with creating a web app for iOS and testing some of the new features in mobile safari that were released with iOS 5. Fixed divs and the ability to scroll a div are common in iOS native apps but were difficult to implement in a web app. These have both been added in the new safari but they still require some work-arounds to make them function like you probably want.
Fixed Elements
The first versions of iOS didn’t support fixed elements. They would fix correctly to the screen, but then they would scroll along with the rest of your content. In iOS 5, fixed elements (e.g. position: fixed; bottom: 0;) work as expected.
Keep in mind you’ll want to use the iOS meta tags if you’re designing specifically for the device. The first line below prevents the default scaling for sites that aren’t built for to adapt to the screen size and the second allows you to save the site and run it without the browser bars.
<meta name="viewport" content="initial-scale = 1.0, user-scalable = no">
<meta name="apple-mobile-web-app-capable" content="yes" />
The first issue with the fixed elements is that your site will still have the ‘bounce’ effect when scrolling past the top/bottom of your content that reveals the browser chrome (background beneath your page as it bounces). If your site doesn’t need to scroll this is a very simple fix, just add a line to prevent the default action when moving your finger:
<script type="text/javascript">
document.addEventListener('touchmove', function(event) {
event.preventDefault();
}, false);
</script>
If you want scrolling areas, but don’t want the browser chrome to show then continue on!
Scrolling Divs
Another new feature in iOS 5+ is divs can finally scroll. To make a div scroll you’ll just need to add the following (this example has a fixed header but adjust the positioning to fit your app):
.scrollable {
position: absolute;
top: 50px;
left: 0;
right: 0;
bottom: 0;
overflow: scroll;
-webkit-overflow-scrolling: touch;
}
The trick here is adding the -webkit-overflow-scrolling to anywhere you’d normally set your overflow. The downside of Apple’s implementation is that the div doesn’t bounce as you’d hope when you are already at the absolute top or bottom. Instead of bouncing the div being scrolled, it bounces the whole page and reveals the browser chrome. This is where you’ll need a javascript fix.
Fixing the Scrolling Element
Thanks to the development community there are several great options out there that you can implement. These include Scrollability and iScroll. My issue with iScroll was that it doesn’t play well with form elements if you have them in your app. At the time of this article, Scrollability’s author says it isn’t ready for release usage, but it seems to be a great solution if you want to test it. If you want your app to work well with old implementations of iOS you’ll need something similar to this (plus you’ll also need to code around the fixed elements issue), but for now we’re only addressing iOS 5+ and we’ll will save fallbacks for a different article.
The solution I like the best for iOS5 is also the simplest. Joe Lambert’s ScrollFix increases the page slightly when at the top or bottom to make your div bounce instead of the whole browser. It’s very simple to add to an element that you already have scrolling:
<script type="text/javascript" src="scrollfix.js"></script>
<script type="text/javascript">
var scrollingContent = document.getElementById("myScrollingDiv");
new ScrollFix(scrollingContent);
</script>
If you have multiple scrolling divs just apply this again to those divs. For my app I’ve got several divs which either shown or hidden and each has this script applied. We’re almost there, but two possible issues still exist. When scrolling on our fixed elements and our scrolling elements that don’t have enough content to overflow the page, the browser chrome is still revealed.
Preventing Fixed Headers from Showing Browser Chrome
This is a pretty simple fix, similar to what was described above. In my fixed header I’ve got multiple elements, so I made sure that each element or it’s parent had the class “noBounce” and then applied the following script:
document.addEventListener('touchmove', function(event) {
if(event.target.parentNode.className.indexOf('noBounce') != -1
|| event.target.className.indexOf('noBounce') != -1 ) {
event.preventDefault(); }
}, false);
This prevents the default bounce when dragging those classed elements, but doesn’t break the div that you want to scroll.
Adapting for Elements That Don’t Overflow
When creating my code some of the divs for my main content overflowed the browser window which triggers the scrollbar and bounce fix, but others didn’t. There are several ways to address this, but the easiest solution I came up with just extends all divs so they have at least a bit of scroll. To do that I added this jQuery script (you could do something similar in straight JS as well) to all my content divs:
<div class="scrollable">
<div class="contentWrapper">
Your content
</div>
</div>
<script type="text/javascript">
$('.contentWrapper').css('min-height', $(window).height() - 55 + 'px');
</script>
You’ll need to adjust the “- 55″ portion based on your application. I have it in there to prevent it from having too much scroll because of my fixed header.
Here’s a really basic demo if you want to test it out in your mobile browser: kylejlarson.com/files/iosdemo/
An Event Apart Minneapolis
Last week I had the opportunity to attend An Event Apart (AEA) when it stopped by Minneapolis. AEA is a conference “for people who make websites” taught by some of the best known names in web design. I had seen Jeffery Zeldman, Jason Santa Maria, Jeremy Keith, Jared Spool, Kristina Halvorson, and Luke Wroblewski speak at various trips to Austin for South by Southwest (SXSW), but all these talks were fresh content.
Every speaker did a great job and had tons of good information, but a few of the talks stood out and got me really excited about what I was learning. The talks that were the most inspirational for me were Eric Meyer’s talk about using flexible boxes, Nicole Sullivan on optimizing CSS, and Ethan Marcotte on responsive web design. The future of designing sites for multiple devices looks very promising with the combination of the flexible boxes and responsive design (media queries). The great part is that the boxes allow content to be reordered for different purposes where it has previously been difficult to do using floats (without absolute positioning). If you don’t know about media queries check out the original responsive design article.
If you’ve got a chance to attend An Event Apart I’d highly recommend it. While it didn’t have the variety, scale, or full immersion in a sea of web geeks like SXSW, it had many of its own benefits. At AEA there weren’t giant lines, missed panels that were at capacity, or most importantly – panels that didn’t have any valuable content. There wasn’t a session here that didn’t deliver! Overall it was a much more focused and professionally delivered effort (food was also great and I got to sit next to Zeldman at lunch!).
I put together a PDF of my AEA notes if you’d like to get an idea of what was covered.
How to Create Pie Charts with CSS3
Last week I decided to update my online resume to make it a little more graphical, because well… I’m a designer. The first step was coming up with some good ways to represent data, and pie charts seemed like a good fit to show skill development. Pie charts are pretty simple to create using a spreadsheet program or a drawing program, but I wanted something out of the ordinary that didn’t require creating new graphics every time I update them. It seemed like it should be possible with the new capabilities of CSS3 so I started working on a solution.
The two most promising things I found were Google’s Chart Wizard, (which uses javascript) and a CSS3 Pie Chart Article from Atomic Noggin. I wanted to do something purely with CSS & HTML so I took the ideas from that article and tweaked them a bit to get the result that I wanted.
There were a few things that I wanted to do differently from the original article:
- In the article the pie pieces are pulled out from the sphere and I wanted a solid circle.
- Once aligned as a solid sphere there were some rendering issues (in some browsers) aligning clipped shapes next to each other that left gaps between the shapes.
- I wanted to be able to add styles to the full sphere such as a border or drop-shadow.
Creating a Drop-Shadowed Circle
My first step was creating a circle that will be the bottom layer of the chart. This bottom circle will also hold any border or drop-shadow style. Additionally, I’ve put a div with a set height around the circle so it stays inline with the content (as the circles will be absolutely positioned to stay on top of each other). To create a circle, simply add a border-radius that is half the pixel value of the width of a square div. You’ll notice below I’ve used browser specific css tags (e.g. -moz-border-radius) for the CSS3 elements. Currently CSS3 support is varied between browsers. Eventually, as full support is included in browsers, you won’t need them any more and this will be much simpler to manage.
<style>
.pieContainer {
height: 100px;
}
.pieBackground {
background-color: grey;
position: absolute;
width: 100px;
height: 100px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-o-border-radius: 50px;
border-radius: 50px;
-moz-box-shadow: -1px 1px 3px #000;
-webkit-box-shadow: -1px 1px 3px #000;
-o-box-shadow: -1px 1px 3px #000;
box-shadow: -1px 1px 3px #000;
}
</style>
<div id="pieContainer">
<div class="pieBackground"></div>
</div>
Adding a Slice of the Pie
Next you’ll want to create a half circle by using clipping to hide the 2nd half. Unless you want exactly 50% you’ll need to change the size of that circle by dropping it inside of a div that controls the rotation and use the inner div to adjust the size. For the first slice we’ll start the outer div at 0 degrees, which is the default, so we’ll only need to edit that for additional slices. (* Note that I’m adding to the code above and only displaying the new CSS.)
<style>
.pie {
position: absolute;
width: 100px;
height: 100px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-o-border-radius: 50px;
border-radius: 50px;
clip: rect(0px, 50px, 100px, 0px);
}
.hold {
position: absolute;
width: 100px;
height: 100px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-o-border-radius: 50px;
border-radius: 50px;
clip: rect(0px, 100px, 100px, 50px);
}
#pieSlice1 .pie {
background-color: #1b458b;
-webkit-transform:rotate(50deg);
-moz-transform:rotate(50deg);
-o-transform:rotate(50deg);
transform:rotate(50deg);
}
</style>
<div class="pieContainer">
<div class="pieBackground"></div>
<div id="pieSlice1" class="hold"><div class="pie"></div></div>
</div>
Large & Multiple Slices
If you’d like to make a slice take up more than 50% of the pie you’ll just need to add another pie div of the same color with a hold div wrapped around it. To add a slice in a new color just change the background color. Below is an example of making a slice over 50% and a second slice of a new color.
<style>
#pieSliceBlue .pie {
background-color: #1b458b;
-webkit-transform:rotate(180deg);
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
transform:rotate(180deg);
}
#pieSliceBlue2 {
-webkit-transform:rotate(180deg);
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
transform:rotate(180deg);
}
#pieSliceBlue2 .pie {
background-color: #1b458b;
-webkit-transform:rotate(40deg);
-moz-transform:rotate(40deg);
-o-transform:rotate(40deg);
transform:rotate(40deg);
}
#pieSliceRed {
-webkit-transform:rotate(220deg);
-moz-transform:rotate(220deg);
-o-transform:rotate(220deg);
transform:rotate(220deg);
}
#pieSliceRed .pie {
background-color: #cc0000;
-webkit-transform:rotate(140deg);
-moz-transform:rotate(140deg);
-o-transform:rotate(140deg);
transform:rotate(140deg);
}
</style>
<div class="pieContainer">
<div class="pieBackground"></div>
<div id="pieSliceBlue" class="hold"><div class="pie"></div></div>
<div id="pieSliceBlue2" class="hold"><div class="pie"></div></div>
<div id="pieSliceRed" class="hold"><div class="pie"></div></div>
</div>
IE Fallback
As expected, this doesn’t work in any Internet Explorer browsers below version 9. If you’re concerned about IE users, a simple way to fix this is adding a conditional comment for IE with a jpg of whatever charts you’re trying to display.
URL Structure Tips
When working through the architecture and coding of a website the URL structure is often overlooked. Carefully considering the location of your pages can greatly help users by making links semantic and easy to remember. It’s easiest to start this process when doing a redesign or a new site, but its worth investing the time and effort at any point.
When determining your URL structure, the first place to start is with your site’s architecture (site map / navigation). The structure of your URLs should reflect how your users navigate your site. Typically, you’ll want to find large buckets and group your content using directories (yourdomain.com/company – yourdomain.com/products – yourdomain.com/articles). You should have an index page in each of those directories that leads to any additional content within, which can be in their own subdirectories. Apple does a good job of this, creating consistant URLs where expected, like apple.com/iphone & apple.com/iphone/features.
Folders vs Subdomains
I recommend using subdomains (e.g. products.yourdomain.com), as alternative to folders, only when there is a clear division of content. For example if you ran a second site that is intended for another purpose entirely from your main site, such as a site for investors, a subdomain may be a good choice. In Apple’s case they keep their marketing product information at apple.com and their online store at store.apple.com. There are several reasons for this, but the biggest two in my mind are that search engines typically consider subdomains as a different site when indexing and that many users aren’t savvy enough to understand subdomains (if you create them make sure you can type www before the subdomain and it will still forward correctly).
Dynamic Pages
Semantic URLs can become difficult when creating dynamic product or article pages. There are many sites with pages like this domain.com/store/product.php?id=1234 instead of something more logical like domain.com/store/productName. If you’re using blog software like WordPress you can easily change this setting. In WordPress simple go to settings > permalinks and choose one of the available options or create your own structure. For users of CMS systems take a look and see if such an options is available; if not take a look on google for “URL Rewriting” to create custom paths to your content.
Design Process: The Rule of Three
Having a solid web design process is critical for efficiently creating quality work. On Happycog’s Cognition Blog, Chris Cashdollar posted about their process of creating three unique designs to present to a client. When I first started doing freelance work for clients I followed the rule of three without question, but over time I’ve changed my process based on the project that I’m working on.
The Benefit of Three
Overall, following the rule of creating three mockup designs for a project is useful for many of the reasons that Chris mentions in his article. Creating multiple designs forces you to solve the same problem in a variety of ways and each subsequent design is informed by your previous discoveries. It also shows your client that you’re focused on delivering options that best fit their goals and helps foster discussion over the solutions.
Third Wheel
While creating three designs has many benefits, I no longer follow it as a hard rule. There are two reasons I suspect that the rule of three is more effective in Chris’s case:
- Happy Cog’s projects are likely larger in time and scope than mine
- Chris mentions having a separate designer for each design
Nearly all of my projects are designed by myself with input only from the client (and sometimes friends if I want some other feedback). This, combined with most projects being quicker and on a smaller budget, means that often presenting three full designs isn’t always an effective option. I feel with the total hours allotted to the project, my time is often better spent focusing on one or two well thought-out designs. Also on smaller projects the third iteration can feel like a chore, and it isn’t as innovative as the first concepts where a lot of the discovery took place.
An Alternative Process for Freelancers
The number of concepts I present to a client depends on the project. For a small job, I typically focus on generating one or two concepts and then iterating based on feedback. I find that much of the creativity lost by not doing three designs can be generated in the initial sketching phase. By sketching out designs before getting onto the computer, I can quickly come up with many different ideas and then take several into a larger, more detailed sketches. Following this process, it’s easy to see what is going to work and what doesn’t work so well. Sketches can also be shown to the client for feedback before coming up with your final concept to present. Working this way also helps prevent clients requesting a “frankendesign” combining elements of each of the three designs you show them. I prefer to work this way, rather than trying to force three designs, as each client has a different budget, different expectations and a different level of involvement in the process.
How to Setup Your Site for the iPhone
I’ve been working on some mobile apps lately and realizing how simple it is to get started making your site more iPhone compatible. You can either create a separate site specifically for mobile or create a mobile stylesheet to be applied to specific devices. There are some great arguments out there for each option, but what I’m discussing here is just the introductory steps that work for either method. In writing this I’m also considering how I’d like to apply those ideas to my site here.
If you’re planning to create an additional stylesheet rather than a completely new codebase, you’ll want to start by specifying the stylesheet to use with a media query. Ethan Marcotte has a great article called Responsive Web Design that expands upon this idea on A List Apart. To target an iPhone/iPod specifically you can use this code right after your main stylesheet in your header:
<link media="only screen and (max-device-width: 480px)" href="iphone.css"
type="text/css" rel="stylesheet">
Control the Page Size
Next you’ve got a handful of settings that will help make your site similar to a native iPhone app. If you want your page to resize to the device, you can use this line in your header:
<meta name = "viewport" content = "width = device-width">
or if you’re setting your page width in CSS and would prefer to use a specific scale (with or without the option to disallow users from zooming the page) you can use:
<meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no">
Add a Custom Icon & Startup Image
There are also meta tags for use when your site is added to the home screen of a user’s device (press the ‘+’ in mobile safari to add to the home screen). The first is adding a custom icon to your site that I wrote a previous post about. In addition, you can add a startup screen to give an app like feel. To add a startup image create a png that is 320 x 460 pixels and add this line of code to the header:
<link rel="apple-touch-startup-image" href="/your_image.png">
Make it Look Like an App
You can make your site look more like an app when people save it to their home screen by hiding the top bar that loads with safari and changing the color of the status bar. Before you do this you’ll want to make sure you’re site is setup so it can be easily navigated without needing the back button. To remove the Safari controls add this meta tag to your header:
<meta name="apple-mobile-web-app-capable" content="yes" />
And to change the status bar (network name, time, battery level) from the default grey to either “black” or “black-translucent”:
<meta name="apple-mobile-web-app-status-bar-style" content="black">
Note that if you change the status bar to translucent the site will sit underneath it. Make sure that there is no critical content hidden behind the bar.
These simple lines of code are a great way to get started setting up your site for Apple’s devices. If you’d like to go into some more detail, Apple’s Safari Reference Library is a great place to get started. Then to take this to the next level I’d recommend digging into jQTouch or Sencha. Both of these tools will create an even more app-like experience with animated transitions and app-like bars & buttons using javascript (which you’ll want to have a strong knowledge of to use to their full potential).
How to Make Your Web Statistics Actionable: Search
If you were ill and your doctor handed you a chart including your weight, heart rate, and blood pressure and promptly sent you on your way with no analysis or feedback, he wouldn’t be your doctor for long. Without actionable analysis of the data it has very little usefulness. Website statistics are often discussed in a similarly meaningless way. I’ve suffered through many meetings where people throw around numbers with nothing more to say about them than this number has increased and that one has decreased. Most sites have some statistics available and maybe they are even reviewed occasionally, but to get real value from your statistics they must be a catalyst for action. Analyzing your on-site search and search engine keywords is a great place to get started.
On-Site Search Analysis
If you have a search box on your website it provides one of the greatest sources of immediately actionable data. You should be able to find this data in your statistics either through a specific listing of the search terms entered or by searching page view stats for the query string you’re using to run the search (e.g. yoursite.com/search?q=keyword – just leave out the keyword to see all the keywords entered). From these results you can not only gather information about what people are most interested in, but also a wealth of data to start testing with and improving your site.
The first thing you’ll want to do with the on-site keyword list is plug them into the search box on your site beginning with the most entered keywords. Are you getting the results you would expect? If so thats great. If not you should note any lack of relevant results and add those keywords to the pages that should be showing up. By starting with the most entered phrases and working down you’re going to be rapidly improving search and your user’s experience. Also, check your search results page to see if it has a high bounce-rate (users exiting the site from this page). If this is the case carefully check for quality search results and consider all the possible results the searcher may be after.
In addition to improving search, these search phrases can help inform you about the usability of your site and the best language to communicate with your users. For your most popular searches make sure that not only the results are relevant, but that the content is also discoverable to users browsing your site. Many users will search as a quick means to finding what they are looking for, while others search as a last resort after unsuccessfully looking through your navigation. These popular search keywords also can help guide the language you use in your content. Many companies use insider language to describe services and products while the average user’s language may be completely different (think notebook vs laptop or Form 1040 vs income tax form). Take this search data and use it to communicate more effectively with your user-base.
Finally, compare this data over time. Are popular searches based on the content you are creating at those specific times or is there a trend that you can detect to better schedule your updates and marketing? If you can make a correlation between time and interest (e.g. Item A does well in the winter or Topic B is most searched near school enrollment) you’ll go a long way to improving the results of your efforts.
Incoming Search Engine Keywords
Statistics tracking will also provide you with keywords that users are entering into search engines to find your site, such as Google, Yahoo, or Bing. This data isn’t as immediately impactful as your on-site search, but there is still some actionable information to be found. The primary use is search engine optimization (SEO) in relation to search-user interest.
By reviewing the incoming search terms for your site, you will see where you are ranking well and reaching visitors in search engines. This is data is invaluable, but what we’re looking for here is actionable data. Take a look at the keywords; are users finding good content for what they are searching? Look for those popular keywords and make sure you’ve got great content for your users. If you’re ranking highly for a particular phrase that is not a focus on your site there may be potential for emerging or expanding market (e.g. you sell office widgets and people are searching for health care widgets). Finally, compare this data over time as discussed for on-site keywords. Take any data gathered from search engine keywords with a grain of salt, as your ranking for these terms will change constantly and can be the cause for fluctuation in traffic.
While this article is focused on only the search aspect of statistics but with such a large topic I plan to follow up on this article in the future with other ways to improve the use of web stats. Hopefully some of these ideas will take your use of web statistics being just an observer and toward something actionable.
Adding an Icon for iPhone, iPad & Android to Your Website
Many sites currently add a favicon before launch that is visible in your user’s browser tabs and bookmarks, but many sites are still missing icons for iOS. By adding an iOS icon, anyone who decides to save your webpage to the home screen of their iPhone, iPad, or Android* will see a nice app-like icon rather than an image of your page.
The first step is creating an image. To support the newest high resolution iPhone you’ll want to create the image at 114 x 114 pixels or larger (the device will resize the image to the correct dimensions). You can save your image as a PNG (if you plan to use transparency) or a JPG and place it in any directory on your site.
![]()
Next you’ll just add a simple bit of code to the HEAD of your site so the devices can find your image:
<link rel="apple-touch-icon" href="images/your_ios_icon.png" />
By default Apple devices will add rounded corners, a drop shadow, and reflection to your icon. If you don’t want those styles added or you’d prefer to add your own styles to the image file (like I did for my icon) you can use apple-touch-icon-precomposed instead.
<link rel="apple-touch-icon-precomposed" href="images/your_ios_icon.png" />
If you’re creating a precomposed image you can find templates for use around the web; here’s a good template from cocoia with Photoshop effects you can turn on/off.
* Note on Android Devices: versions 1.5 & 1.6 work with the “-precomposed” images only and 2.1 & new will read the tag without “-precomposed”.
HTML 5 Video with Flash Fallback
HTML5 has some exciting new changes, most notably tags for embedding audio and video. Currently not all browsers will fully support these tags, but with the ability to fallback on different formats until one that works for your browser you can start using them today. The greatest benefit of using HTML5 video tags right now is its compatibility across multiple devices, notably mobile devices. The majority of mobile devices, including the iPad and iPhone, are currently unable to run flash based players. Adding the video tag allows these browsers to play your videos with their built in controls, expanding your potential audience.
Video Formats
The first item to look at when setting up the video tag is your video formats. Web browsers don’t currently agree on which video format should be the leader for the web so to support them all we’re currently stuck providing video in multiple formats. The two most common formats right now are H.264 (typically .mp4) and Theora (typically .ogv). H.264 is great format and common across the web as YouTube and the iTunes store both use it, but has a disadvantage in that MPEG LA owns the patent to the format and could potentially charge to encode videos in the future. Theora has the benefit of being royalty-free, but isn’t currently as widely used or integrated into as many tools. Currently Firefox and Opera only support Theora, while Safari (iPhone & iPad), Android, and Flash only support H.264. Internet Explorer is behind in supporting the video tag, which makes the ability to fallback to a Flash based player very useful.
Encoding Video
To encode .ogg files I’ve used Firefogg, which is a plugin for Firefox. This tool makes it very simple to create ogg files (for batch encoding try ffmpeg2theora). Simply install the plugin and then in FireFox go to the “Tools” menu and select “Make Web Video”. From there select a file that you’ll convert and if you want you can change the output settings for quality or video size. Make sure to leave the default video and audio codecs of Theora and Vorbis both set.
To encode h.264 files I recommend HandBreak. To get started open the video file you want to convert. Choose the iPhone & iPod Touch Default settings in the right menu (window > presets drawer if its not up). Next you’ll want to set the dimensions of your video (Picture tab on PC / Window > Picture Settings on mac). Choose either a specific size you want or change it to match the source settings (as they have changed to a size specific to the iPhone). Check the “Web Optimized” box and in the video you can adjust the quality if necessary to keep your file small. If your video has audio click on that tab and change the setting to “AAC (faac)”. Now you’re ready to encode, either click start or add to queue and repeat this process with another video.
Setting up the Video Tag
If you got all the conversions done correctly, now is the easy part. Simply add a video tag with the height and width of your video. Adding “controls” to the tag will allow the user to pause/play the video and adjust the volume (other options for the video tag include preload, loop and autoplay). Then list the source location of the videos you created above in the order you want browsers to attempt to play them. If they are unable to play the first file they will continue to the next one.
<video width="710" height="400" controls>
<source src="video_file.mp4" type="video/mp4" />
<source src="video_file.ogv" type="video/ogg" />
</video>
Tips: The iPhone currently reads only the first video source so you’ll want your mp4 file listed first. If you’re maintaining your own server you’ll want to make sure you have these MIME types added: video/ogg .ogv & video/mp4 .mp4.
Falling back to Flash
The next step to cover yourself for old browsers and the always behind Internet Explorer is adding a Flash Player to the end of the video tag. The nice thing is this will work just like it did for the video files, if the first two don’t work it’ll move right on to the Flash. You can add in whichever Flash player you’d like to use, but my preferred player is the JWPlayer, so thats what I’ll be using.
<video width="710" height="400" controls>
<source src="video.mp4" type="video/mp4" />
<source src="video.ogv" type="video/ogg" />
<object width="710" height="424" type="application/x-shockwave-flash"
data="js/player.swf?image=image.jpg&file=video.mp4">
<param name="movie" value="js/player-licensed.swf?image=image.jpg&file=video.mp4" />
</object>
</video>
That’s all there is to setting up an html 5 video tag. Here’s a sample:
Related Links
Here’s a few projects and informational sites to check out for html video:
Building a Dock with CSS Animation
After seeing some interesting uses of CSS animation, I decided to make a fisheye dock using only html, css and some images.
Currently not all browsers will support the functionality, but it will function correctly in Webkit browsers (Chrome / Safari) and Opera. The latest full release of Firefox (as of the writing of this article) doesn’t support css transitions so it won’t have the nice fade effects.
Dock Setup
The first step is to create some transparent PNGs to use as images for the dock. Then add the images to a list and put the text for the image in a paragraph tag. I’m also adding a div tag that we’ll use later in setting up a text bubble.
<ul id="dock-container">
<li>
<a href="#"><img src="images/catalog.png" alt="catalog" />
<p>Catalog</p><div></div></a>
</li>
<li>
<a href="#"><img src="images/passkey.png" alt="passkey" />
<p>Login</p><div></div></a>
</li>
<li>
<a href="#"><img src="images/certification.png" alt="certification" />
<p>Certification</p><div></div></a>
</li>
<li>
<a href="#"><img src="images/mountbuilder.png" alt="mountbuilder" />
<p>MountBuilder</p><div></div></a>
</li>
<li>
<a href="#"><img src="images/rackbuilder.png" alt="rackbuilder" />
<p>RackBuilder</p><div></div></a></li>
<li>
<a href="#"><img src="images/videos.png" alt="videos" />
<p>Video</p><div></div></a></li>
<li>
<a href="#"><img src="images/calculator.png" alt="calculator" />
<p>Calculator</p><div></div></a>
</li>
<li>
<a href="#"><img src="images/mobileSite.png" alt="mobile site" />
<p>Mobile</p><div></div></a>
</li>
<li>
<a href="#"><img src="images/savedProducts.png" alt="saved products" />
<p>Saved</p><div></div></a>
</li>
</ul>
Next add some CSS to float the images in a horizontal line and lower their size in the default state so they don’t become pixelated when they are zoomed.
#dock-container {
font: Helvetica, Arial, sans-serif;
font-size: 12px;
}
#dock-container li {
float: left;
list-style-type: none;
text-align: center;
}
#dock-container a {
color: #ccc;
text-decoration: none;
}
#dock-container img {
border: 0;
width: 75px;
}
Text Bubbles
Before we add the animations, we’ll stylize the text below the images to make them look like speech bubbles. The bubble is created using border-radius and the arrow using our first transform to rotate the empty div created above forty-five degrees.
#dock-container p {
background: #000;
border-radius: 8px;
-moz-border-radius: 8px;
margin: 0;
position: relative;
padding: 2px 4px;
z-index: 100;
}
#dock-container div {
background: #000;
width: 10px;
height: 10px;
margin: 0 auto;
position: relative;
bottom: 20px;
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
CSS Transitions & Animation
Now we’ll add the CSS to animate the menu. First we’ll define the transition that we’ll apply to all the animation effects on images and paragraphs so they fade (ease) both in and out. After that I’m going to define a transition specifically for the opacity transformation because I want it to show up much faster. Finally, we add the scale transformation to increase the size of any images by 1.4x within the link tag when its hovered over.
#dock-container img, #dock-container p {
-moz-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
}
#dock-container p, #dock-container div {
-moz-transition: opacity .1s ease-in-out;
-o-transition: opacity .1s ease-in-out;
-webkit-transition: opacity .1s ease-in-out;
}
#dock-container a:hover > img {
-moz-transform: scale(1.4);
-o-transform: scale(1.4);
-webkit-transform: scale(1.4);
}
Finishing the Text Bubbles
We’ve just about got a working menu now. The final step is just getting the text bubbles to display only when the links are hovered. To do this we’ll just add opacity of 0 to those elements and then change it to 1 when hovered. The transition we set in the last step will quickly fade it in and out.
#dock-container p, #dock-container div {
opacity: 0;
}
#dock-container a:hover > div, #dock-container a:hover > p {
opacity: 1;
}



