Scott Gale Scott N. Gale
Vermont
Scott Gale's RSS Feed Scott Gale's LinkedIn Page Scott Gale's Facebook Page Scott Gale's Twitter Page

Archive for the ‘Web Development’ Category

Coverflow using CSS 3D Transforms

May 24th, 2011 - by Scott Gale - Add Comment »

As HTML5 and CSS3 technology grows, WebKit CSS 3D transforms are emerging and allowing web developers to do some great things within the browser. To exemplify this, I’ve put together a CSS coverflow demo that functions inside the browser using CSS 3D transformations, reflections, multiple background attachments, and touch events.

View the Demo (best in Chrome or Safari)CSS Coverflow 3D Transforms for WebKit

This works on the iPad and iPhone as well using gestures, swipe left to right or right to left to change the item. This example uses Paul Bakus’ code as a base and building it out with lots of new tech.

Here is the step by step on how I built it.

Step 1: Create Perspective

To build the CSS 3D transform you have to first find your wrapping div and add -webkit-perspective: 500px; to it. For this I used the “bd2″ class wrapper.

.coverflow .bd2 {
   -webkit-perspective: 500px;
   margin: 0;
   height: 60%;
   border: none;
   overflow: hidden;
   width: 100%;
   position: relative;
}

The perspective gives the illusion of depth on the z axis.

Step 2: Apply the CSS 3D Transform
Then apply the CSS 3D transform rotation depending on the location of the image:
var webTransform = "rotateY("+(side === "right"? 55 : -55 )+"deg)";

When the transform is applied it uses the perspective to calculate how much movement is required. You can play with this by expanding and contracting the window to see how the browser deals with it. The perspective code is very important, your rotation won’t work without you defining it.

Step 3: Enhance the view with the reflection
To do the reflect was pretty simple. I used the -webkit-box-reflect with a transparent gradient so that it would fade the reflect out. Here is the code:

.coverflow .hproduct img {
   -webkit-box-reflect:
      below 0px
      -webkit-gradient(linear, left top, left bottom,
         from( transparent ), color-stop(0.5, transparent),
         to( rgba(50,50,50,0.7) )
}

You also have to make sure that your containing div is tall enough to pick up the reflect. I placed some webkit specific code in there because for other browser’s it doesn’t need to be as tall.

@media screen and (-webkit-min-device-pixel-ratio:0) {
   .hproducts .hproduct {
      height:225px;
   }
}

Note: All subsequent steps are extra enhancements to make the coverflow that much better.

Step 4: Allow for scaling
There are a few cool tricks I used to make this allow for scaling. By using multiple background attachments I was able to allow for the slider to scale as the window size changes. Here is the example:

.coverflow .slider {
   position: absolute;
   bottom: 5px;
   left:0;
   margin:0 10%;
   width: 80%;
   height: 19px;
   background: url(files/scrollbar-left.png) no-repeat top left,
            url(files/scrollbar-right.png) no-repeat top right,
            url(files/scrollbar-center.png) repeat-x;
}

I also put a width of 100% on the containing div to allow for it to scale.

Step 5: Capturing the touch gestures
I attempted to use jswipe for this to no avail. So, my solution was to attach a couple events and code this without the help of a plugin. The key to this is 3 events: touchstart, touchmove, touchend. Here is how I utilized these:

document.ontouchend = function() {
   //swipe left
   if( self.swipeLeft && self.swipe ) {
      self.moveTo(self.current-1);
      $("div.slider").slider("moveTo", self.current, null, true);               
   //swipe right
   } else if(self.swipe) {
      self.moveTo(self.current+1);
      $("div.slider").slider("moveTo", self.current, null, true);
   }            
}

document.ontouchmove = function(e){
   //move only if you swipe across
   if( Math.abs(e.touches[0].pageX - self.startX) > 150 ) {
      if( (e.touches[0].pageX - self.startX) > 5 ) {
         self.swipeLeft = true
      } else {
         self.swipeLeft = false;
      }
      self.swipe = true;
   }
}

document.ontouchstart = function(e) {
   self.startX = e.touches[0].pageX;
   self.swipe = false;
}

Basically this detects the range of your swipe and if it is from left to right large than 150 pixels it moves the images accordingly. The ontouchend can be replaced with any function to perform the needed action. The W3C has recently posted a link for touch events here: http://www.w3.org/TR/touch-events/

Step 6: Deal with all the other browsers
Believe it or not, not every browser is equal, so to build out this I used the philosophy of progressive enhancement.

So here are some samples based on what features you have:

If you have no JavaScript, you get something similar to this:
CSS Coverflow No JavaScript Fallback

Running IE7, you get something like this:
IE7 CSS Coverflow

Running FF, you get something like this:
FireFox CSS Coverflow Image

Step 7: Rejoice! You made it.
There are a number of great techniques used for this all rolled into one. CSS -webkit-box-reflect, CSS RotateY, multiple background attachments, touchstart, touchmove, touchend, and browser compatibility handling. These are exciting new additions to browser technology. Browsers are evolving to make our tasks as designers and developers easier. It’s an exciting time to be a web developer.

How to build a WordPress HTML5 theme

April 22nd, 2010 - by Scott Gale - 3 Comments, Add »

iPhone, iPad, video HTML5 deployment, Webkit, Chrome, Safari, web standards, canvas elements, and disappearing flash support.  These are just a few of the many reasons to explore HTML5 and its capability.  Add WordPress, a very customizable system that allows skinning of the underpinning code in order to achieve the desired result and you get a great basic test case for HTML5.

What follows is quick synopsis of how to setup an HTML5 WordPress skin and some of the benefits this brings:

To start, I setup basic HTML5 markup.  Utilizing new tags.  Here is what the structure looks like:

Using this basic system as a framework, I added microformats to the header and footer for human and machine readable information.  You can view the source and search for “vcard” to see my microformat header.

Next, I started utilizing some of the great things that HTML5 and CSS3 have to offer.  HTML5 has new form field types that work well for the iPad, iPhone, and Webkit.  In other browsers they fall back to be standard text input fields so it’s not a problem to use them in general markup, even for IE6 (everyones favorite).  Here is a breakdown of some of the new HTML5 form fields:
<input type=”search” placeholder=”SEARCH” value=”"/>
The new search input type has a really cool attribute called “placeholder”.  Placeholder is a value that disappears when the form field focuses, a function that we no longer have to emulate with JavaScript on browsers that support this.  The type search also tells the iPhone, iPad, and future dynamic keypads to use a different “enter” key.  Note how the iPad shows “Search” on the keyboard:

<input type=”email”/>
This field type also tells mobile devices to change their keyboard accordingly.  Here is an example of the iPad keyboard with this field type:

<input type=”url”/>
This field type also tells mobile devices to change their keyboard accordingly.  Here is an example of the iPad keyboard with this field type:

Now its time to add the CSS.  Using CSS3 for rounded corners, drop shadows, and gradients, quickly eliminates the need for extra divs, classes, and most importantly, images. I used these styles to do the buttons, the input fields, header and footer styling, and even the background. Here are some of the basic CSS3 styles used:

/* create the body gradient */
body {
	background: -moz-linear-gradient(top, #fff, #ccc);
	background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
}
/* do the rounded corners and drop shadow on the header */
header {
	-moz-border-radius-topleft:8px;
	-webkit-border-top-left-radius:8px;
	-moz-border-radius-topright:8px;
	-webkit-border-top-right-radius:8px;
	-moz-box-shadow: 0px 0px 3px rgba(0, 0, 0, 1);
	-webkit-box-shadow: 0px 0px 3px rgba(0, 0, 0, 1);
	box-shadow: 0px 0px 3px rgba(0, 0, 0, 1);
}
/* create the button for form submission and search submission */
form .submit {
	background: -moz-linear-gradient(top, #073842, #000);
	background: -webkit-gradient(linear, center top, center bottom, from(#073842), to(#000));
}

With these styles it’s quick, easy, and image free to do what use to be a much more arduous process for many of us.

Now you’re all done except for IE

Now that the markup is in place and the styles are in place.  We have to make it work for lesser browsers that can’t handle new standards (aka IE).  There seems to be a misconception out there that this is difficult, but it is actually a few simple steps.  For my blog I conceded that there would be some degradation of the look for browsers that don’t support CSS3 so that makes life easier, and of course it may be a luxury not everyone can afford.

IE Step 1: Add support for styling of the HTML5 tags
To do this, all we have to do is include a JS file called html5shiv hosted on googlecode.com.  This in essence does a document.createElement and a few other things to get IE to recognize the HTML5 elements.  We can wrap this in conditional comments because it is only required for IE.

<!--[if lte IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

IE Step 2: IE specific CSS
For any IE specific CSS that you want to do (I added a few different border treatments and color tones to make the site still look ok) add the IE specific CSS file.

So the sum of your checking for IE should look something like this:

<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  <link rel="stylesheet" href="/blog/wp-content/themes/scottgale/style-ie.css" type="text/css" media="screen" />
<![endif]-->

Make sure after you add this to validate your markup with the w3c validator.  It handles HTML5 quite well from my experience.

And now your are done!

I hope this helps everyone to explore this new web standard.  The blogosphere is an easy place to try this out and help perpetuate these ideas.  Please let me know if I need to explore any of these concepts in more detail for people.

Microformats and SEO

March 18th, 2010 - by Scott Gale - 5 Comments, Add »

For a long time search engines have been making sense of a web development approach that doesn’t incorporate consistent markup for consistent items. Search engines have managed to do a great job with this, however, now we have the advantage of microformats and other Rich Snippets. With microformats we can make both machine readable and human readable code. This concept will encourage SEO professionals to engage web developers as well as become more code savvy themselves.

Microformats are simple standardized ways of organizing website information. Microformats have implications for web development standards, SEO, and application development around parsing website information.

Lately, there has been a lot of discussion around these snippets for SEO, geo tagging, etc. I find this a bit ironic because they have been around for so long.  (The microformat search term on Google hit its peak in 2007.)  However, what hasn’t been around for very long is the Google adoption of all of these “Rich Text Snippets”.  The term Rich Text Snippets includes microformats, microdata, and RDFa’s.  I’ve seen some examples on the microformats blog and Google has been blogging about all the support they have been adding.  Google actually made some mistakes in their examples, but it looks like they corrected them. So I thought I would outline my favorite examples of microformats to get that information out there.  Hopefully we can perpetuate the wide-spread use of these.

These are my favorite markup uses for each format:

Review:

<div class="hreview">
  <span class="item">
    <span class="fn">Scott Gale's Blog</span>
  </span>
  Reviewed by <span class="reviewer">John Smith</span> on
  <span class="dtreviewed">
    Jan 6<span title="2009-01-06" />
  </span>.
  <span class="summary">Love the website</span>
  <span class="description">
    I like your blog because it offers me, an SEM evangelist and
    sales guy, an insight into the world of technology from
    someone who understands the very essence of its infrastructure.
  </span>
  Rating:
  <span class="rating">4.5</span>
</div>

Person

<div class="vcard">
  My name is
  <span class="fn">Scott Gale</span>,
  My blog url is:
  <a href="http://scottgale.com/blog" class="url">scottgale.com/blog</a>.
  I live in
  <span class="adr">
    <span class="locality">South Burlington</span>,
    <span class="region">VT</span>
  </span>
  and work as a
  <span>Web Developer</span> at
  <span>Dealer.com</span>.
</div>

Business:

<div class="vcard">
   <span class="fn org">Scott Gale's Web Shop</span>
   Located at
     <div class="adr">
        <span class="street-address">16 Any Dr.</span>, <span class="locality">South Burlington</span>, <span class="region">VT</span>.
     </div>
     <span class="geo">
        <span class="latitude">
           <span class="value-title" title="37.774929" />
        </span>
        <span class="longitude">
           <span class="value-title" title="-122.419416" />
        </span>
     </span>
     Phone: <span class="tel">206-555-1234</span>
     <a href="http://scottgale.com/blog">scottgale.com/blog</a>
</div>

Product:

<div class="hproduct">
   Make: <span class="brand">Maserati</span>
   <span class="category">Automotive</span>
   <h1 class="fn">Granturismo</h1>
   Nicely equiped for:
   <span class="price">$134,000</span>.
   <span class="description">The Maserati GranTurismo design exudes elegance
   and has room for 4.  Reinvented from the ground up.</span>
   <a href="http://www.scottgale.com/Maserati-GranTurismo" class="url">View Details</a>
</div>

Video: (RDFa from Google’s site)

    <object width="512" height="296" rel="media:video"
      resource="http://example.com/video_object.swf?id=12345"
      xmlns:media="http://search.yahoo.com/searchmonkey/media/"
      xmlns:dc="http://purl.org/dc/terms/">
     <param name="movie" value="http://example.com/video_object.swf?id=12345" />
     <embed src="http://example.com/video_object.swf?id=12345"
       type="application/x-shockwave-flash" width="512" height="296">

     <a rel="media:thumbnail" href="http://example.com/thumbnail_preview.jpg" />
     <a rel="dc:license" href="http://example.com/terms_of_service.html" />
     <span property="dc:description" content="Cute Overload defines Baroo? as: Dogspeak for
      'Whut the...?'Frequently accompanied by the Canine Tilt and/or wrinkled brow for enhanced effect." />
     <span property="media:title" content="Baroo? - cute puppies" />
     <span property="media:width" content="512" />
     <span property="media:height" content="296" />
     <span property="media:type" content="application/x-shockwave-flash" />
     <span property="media:region" content="us" />
     <span property="media:region" content="uk" />
     <span property="media:duration" content="63" />
    </object>

(Would be nice to see a video microformat, they audio spec is in review currently.)

With Google’s adoption of these standards it puts microformats in the running for some serious SEO discussion. Google has a lot of documentation about this. They also have a rich snippet testing tool to confirm that your html is properly formed and able to be parsed.

Also, I stumbled upon a great post by Jay Myers about the potential of these formats and how it relates to SEO.

With Google’s adoption of this it puts microformats as a new and important SEO component. Utilizing the examples above coupled with the tools that Google has for testing will help create a more human and machine readable web. Microformats.org can help get you started if you are interested in becoming a contributor.

My new blog mock in HTML5

March 10th, 2010 - by Scott Gale - 1 Comment, Add »

So this week I discovered http://conceptfeedback.com/ (http://bit.ly/bJk6CO). I know lots of people say, don’t trust the opinions of random people out there but at the same time, that is the internet constituency hitting my site. It is good to have some opinions from a diverse set of people. I loved the opinions that I have received thus far, some good ideas have come out of it. I encourage people to try this service, as long as you review other people’s work it is free to try.

So here is the mockup I posted there, which I have built in HTML5:

New Blog Mockup

You can check out and comment on the new concept in conceptfeedback.com or on this site.  Once I have this fully solidified I will send around my general markup philosophy for setting up a wordpress skin in HTML5.