Mostrando entradas con la etiqueta CSS. Mostrar todas las entradas
Mostrando entradas con la etiqueta CSS. Mostrar todas las entradas

domingo, 7 de agosto de 2011

OS X Lion Interface Buttons in CSS

OS X Lion Interface Buttons in CSS: "
Greepit previously shared New Google Interface Buttons in CSS, today we are sharing another awesome CSS Buttons collection for spice up your user interfaces.

OS X Lion was released recently and part of the new design is new icon buttons. Our friends at Pixify recreated OS X Lion’s buttons in CSS for use in your UI.
The guys simply numbered the buttons 1 to 200 and wrote a three-line script to spit out the CSS for each of the 200 buttons.

Related Posts


"

jueves, 16 de junio de 2011

Five Useful Interactive CSS/jQuery Techniques Deconstructed

Five Useful Interactive CSS/jQuery Techniques Deconstructed: "




 in Five Useful Interactive CSS/jQuery Techniques Deconstructed


With the wide variety of CSS3 and JavaScript techniques available today, it’s easier than ever to create unique interactive websites that delight visitors and provide a more engaging user experience.

In this article, we’ll walk through five interactive techniques that you can start using right now. We’ll cover:

  1. Animated text effects,
  2. Animated images without GIFs,
  3. More engaging drop-down menus,
  4. Fancier slideshow navigation,
  5. Animated icons for the hover state of buttons.

Besides learning how to accomplish these specific tasks, you’ll also master a variety of useful CSS and jQuery tricks that you can leverage when creating your own interactive techniques. The solutions presented here are certainly not perfect, so any thoughts, ideas and suggestions on how you would solve these design problems would be very appreciated.

So, let’s dive in and start building more exciting websites!



1. Extruded Text Effect


Extruded-text-effect in Five Useful Interactive CSS/jQuery Techniques Deconstructed

The footer of David DeSandro’s website uses extruded text that animates on mouseover. This interactive text effect is a quick and impressive way to add some flare to your website. With only a few lines of CSS3, we can make the text appear to pop out of the page in three dimensions.


First let’s set up some text (the code is copied from the original site):

<span class="extruded">Extrude Me</span>

And some basic styling (the code is copied from the original site):

body {
background-color: #444;
text-align: center;
}

.extruded {
color: #888;
font-family: proxima-nova-1, proxima-nova-2, 'Helvetica Neue', Arial, sans-serif;
font-size: 48px;
font-weight: bold;
text-shadow: #000 3px 3px;
}

Here, we’ve applied some basic styles and added a text-shadow. But this text-shadow doesn’t look three-dimensional; to accomplish the extruded effect, we’ll need to add more text-shadows:

text-shadow: #000 1px 1px, #000 2px 2px, #000 3px 3px;

This will add three different text-shadows to our text, stacked on top of each other to create the three dimensional appearance we want.

Styling the Hover State


Next, let’s add a hover state with a bigger text-shadow:

.extruded:hover {
color: #FFF;
text-shadow: #58E 1px 1px, #58E 2px 2px, #58E 3px 3px, #58E 4px 4px, #58E 5px 5px, #58E 6px 6px;
}

Here, we’ve added three more text-shadows to increase the depth of the extrude effect. But this effect alone is too flat; we want the text to look like it’s popping off the page. So, let’s reposition the text to make it appear to grow taller from the base of the extruded section:

.extruded {
position: relative;
}

.extruded:hover {
color: #FFF;
text-shadow: #58E 1px 1px, #58E 2px 2px, #58E 3px 3px, #58E 4px 4px, #58E 5px 5px, #58E 6px 6px;
left: -6px;
top: -6px;
}

Now in the hover state, the extruded text moves up the same distance as our max text-shadow value. We also added position: relative, which must be attached to the base state, not just the hover state, or else it will cause problems when we animate it.

Animating the Transition


Next, we can add a CSS3 transition to our text to animate the color change and extrude effect:

.extruded {
-moz-transition: all 0.3s ease-out; /* FF3.7+ */
-o-transition: all 0.3s ease-out; /* Opera 10.5 */
-webkit-transition: all 0.3s ease-out; /* Saf3.2+, Chrome */
transition: all 0.3s ease-out;
}

This triggers a smooth animation for our different CSS changes on hover. While it doesn’t work in all browsers, it does degrade nicely to the basic hover effect.

Bringing it all together:

body {
background-color: #444;
text-align: center;
}

.extruded {
color: #888;
font-family: proxima-nova-1, proxima-nova-2, 'Helvetica Neue', Arial, sans-serif; /* the original site doesn't use the @font-face attribute */
font-size: 48px;
font-weight: bold;
text-shadow: #000 1px 1px, #000 2px 2px, #000 3px 3px;
position: relative;
-moz-transition: all 0.3s ease-out; /* FF3.7+ */
-o-transition: all 0.3s ease-out; /* Opera 10.5 */
-webkit-transition: all 0.3s ease-out; /* Saf3.2+, Chrome */
transition: all 0.3s ease-out;
}

.extruded:hover {
color: #FFF;
text-shadow: #58E 1px 1px, #58E 2px 2px, #58E 3px 3px, #58E 4px 4px, #58E 5px 5px, #58E 6px 6px;
left: -6px;
top: -6px;
}

Shortcomings


While applying several CSS3 text-shadows works well when the text is static, it falls a bit short when used alongside the transition animation.

In short, the biggest text-shadow animates just fine, but the other text-shadows aren’t applied until the animation completes. This causes a quick correction: the browser stutters with a basic drop-shadow before filling in the rest diagonally.

Fortunately, we can make this drawback relatively unnoticeable, provided that we follow a few style guidelines. Basically, we want to hide the bulk of the extruded portion with the top text. This means that we should generally use this effect with bolder fonts, such as the Proxima Nova family used by David DeSandro. Also, we should be careful to avoid text-shadows that are too big for the font. Tweak your settings with this in mind until the animated extrude looks believable.

Finally, this technique will not work in IE, because text-shadow is unsupported in all versions of IE (even IE9).




2. Animating A Background Image


Animated-images in Five Useful Interactive CSS/jQuery Techniques Deconstructed

While we can easily animate text with a few lines of code, animating an image usually requires bigger and slower assets, such as animated GIFs or Flash or HTML5 video. While complex animations will still depend on these technologies, we can create a compelling illusion of animation using CSS alone.

Love Nonsense uses a hover effect to alter the color of the images on the website. The trick here is to use a transparent PNG with a background color. The color of the PNG should match the website’s background, so that all of the transparent areas in the PNG show up when filled with a background color. Thus, the PNG should contain the negative space of the image you want to display (i.e. the shape you want should be transparent, and everything else should be the same color as the background).

Here’s an example of the Smashing Magazine logo with negative space:

Inverse-negative-space in Five Useful Interactive CSS/jQuery Techniques Deconstructed

Notice in the demo how when the background color is set to orange, it starts to look more like the real thing.

The Code



First, let’s do some basic mark-up:

<div class="post-wrapper">
<h2 class="post-title">
This is the title you hover over

<img src="knockout-image.png" class="post-image" alt="" />
</h2>

<p>Some more text here.</p>
</div>

Here we include a post with a title, our knock-out image and a paragraph of text.

Next, let’s set up some static styles:

.post-wrapper {
position: relative;
padding-left: 240px;
}

.post-image {
position: absolute;
top: 0;
left: 0;
background-color: #bbb;
}

.post-title {
color: #037072;
}

Here, we’ve set up the post’s wrapper with position: relative and with enough padding on the left side to absolutely position the image to the left of our post. We’ve also added a background color to our image; so now the positive space in our PNG shows up as light gray.

Next, let’s add some hover effects:

.post-title:hover {
color: #d63c25;
}

.post-title:hover .post-image {
background-color: #f04e36;
}

Now, when we hover over the title or the image, both will change color.

We can take this effect a step further by animating the transition:

.post-image {
-webkit-transition: background-color 400ms ease-in;
-moz-transition: background-color 400ms ease-in;
transition: background-color 400ms ease-in;
}

.post-title {
-webkit-transition: color 400ms ease-in;
-moz-transition: color 400ms ease-in;
transition: color 400ms ease-in;
}

Here, we’ve added a CSS3 transition to both the image and the title, which will make for a smooth color change animation.

Unfortunately, CSS3 transitions are not currently supported in IE9. However, even in unsupported browsers, the color change will still occur — it just won’t have a smooth animation.

If complete cross-browser support for the animation is important, you could always provide a jQuery version of the animation for unsupported browsers. Bear in mind, though, that jQuery’s animate() method does not support color animations, so you’ll need to use a color plug-in.

Putting all the CSS together:

.post-wrapper {
position: relative;
padding-left: 240px;
}

.post-image {
position: absolute;
top: 0;
left: 0;
background-color: #bbb;
-webkit-transition: background-color 400ms ease-in;
-moz-transition: background-color 400ms ease-in;
transition: background-color 400ms ease-in;
}

.post-title {
color: #037072;
-webkit-transition: color 400ms ease-in;
-moz-transition: color 400ms ease-in;
transition: color 400ms ease-in;
}

/* add the hover states */

.post-title:hover {
color: #d63c25;
}

.post-title:hover .post-image {
background-color: #f04e36;
}




3. Mega Dropdown


Mega-dropdown-menu in Five Useful Interactive CSS/jQuery Techniques Deconstructed

One common design problem with dropdown menus is that they often contain a lot of items. Instead of presenting all of its items in a long single column, Bohemia Design uses a multi-column dropdown. This approach not only looks great, but provides an opportunity to group the links and highlight the most important ones.

Let’s recreate this menu using CSS and jQuery.


Building the Tabs


Ideally, we would start with a lean and simple mark-up…

<nav>
<li><a href="#">Tab 1</a></li>
<li><a href="#">Tab 2</a></li>
<li><a href="#">Tab 3</a></li>
<li><a href="#">Tab 4</a></li>
<li><a href="#">Tab 5</a></li>
</nav>

…and use nav li a, nav > li or nav li to style the list items in the navigation. The child selector doesn’t work in IE6 and nav li would cause problems since there are additional LIs nested in the content area of the dropdown. If you absolutely need the site to work for IE6 users as well (and that’s what you sometimes will have to do), you’ll need to have markup similar to the original mark-up in this example:

<ul id="main-nav">
<li class="main-nav-item">
<a href="#" class="main-nav-tab">Tab 1</a>
</li>

<li class="main-nav-item">
<a href="#" class="main-nav-tab">Tab 2</a>
</li>

<li class="main-nav-item">
<a href="#" class="main-nav-tab">Tab 3</a>
</li>

<li class="main-nav-item">
<a href="#" class="main-nav-tab">Tab 4</a>
</li>

<li class="main-nav-item">
<a href="#" class="main-nav-tab">Tab 5</a>
</li>
</ul>

Next, let’s style these five tabs:

#main-nav {
width: 800px;
height: 50px;
position: relative;
list-style: none;
padding: 0;
}

#main-nav .main-nav-item {
display: inline;
}

#main-nav .main-nav-tab {
float: left;
width: 140px;
height: 30px;
padding: 10px;
line-height: 30px;
text-align: center;
color: #FFF;
text-decoration: none;
font-size: 18px;
}

Although a lot of the CSS is specific to our example, there are a few important styles to note.

First, we’ve defined a height and width for our overall tab area and matched the total height and width of all five tabs, so that we can position the dropdown correctly. Next, we’ve defined position: relative for the tab wrapper, which will allow us to position the dropdown absolutely.

Then, we added list-style: none to the list wrapper, and display: inline to each list item, to eliminate any list styling.

Finally, we floated all of the tab links to the left.

Building the Dropdown


Now, let’s build the dropdown mark-up in one of our tab wrappers:

<li class="main-nav-item">
<a href="#" class="main-nav-tab">Tab 1</a>

<div class="main-nav-dd">
<div class="main-nav-dd-column">
Column content here
</div>
</div>

<div class="main-nav-dd">
<div class="main-nav-dd-column">
Column content here
</div>
</div>

<div class="main-nav-dd">
<div class="main-nav-dd-column">
Column content here
</div>
</div>
</li>

Next, let’s style this dropdown:

#main-nav .main-nav-dd {
position: absolute;
top: 50px;
left: 0;
margin: 0;
padding: 0;
background-color: #FFF;
border-bottom: 4px solid #f60;
}

#main-nav .main-nav-dd-column {
width: 130px;
padding: 15px 20px 8px;
display: table-cell;
border-left: 1px solid #ddd;
*float: left;
*border-left: 0;
}

#main-nav .main-nav-dd-column:first-child {
border-left: 0;
}

Here, we’ve positioned the dropdown absolutely, directly beneath the first tab.

Let’s set display: table-cell on all of the column wrappers, so that they display next to each other. But table-cell is not supported in IE6 or 7, so we’ve used an attribute hack as an alternative for IE6 and 7. This hack places an asterisk (*) before each of the attributes that are specific to IE6 and 7.

Thus, we’ve defined a backup for unsupported IEs, which is simply float: left. This works almost as well as display: table-cell, except that the floated elements don’t match each other’s height, so the borders between columns don’t line up. To avoid this minor issue, we simply remove the border-left using the same asterisk hack.

Finally, we remove the left border from the first column for all browsers. Although the :first-child pseudo-class doesn’t work properly in IE6, fortunately it doesn’t make a difference, because we’ve already hidden the borders in these browsers.

Adding the Interaction


We’ve built the mark-up and styles for our dropdown, but we still need to make the menu interactive. Let’s use jQuery to add a class to show and hide the dropdown:

$(function() {
var $mainNav = $('#main-nav');

$mainNav.children('.main-nav-item').hover(function(ev) {
// show the dropdown
$(this).addClass('main-nav-item-active');
}, function(ev) {
// hide the dropdown
$(this).removeClass('main-nav-item-active');
});
});

Here, we’ve attached a hover listener to each list item, which adds and removes the class main-nav-item-active. Attach this to the list item rather than the tab itself, or else the dropdown will disappear when the user mouses off the tab and into the dropdown area.

Now we can use this class hook to hide and show the dropdown with CSS:

#main-nav .main-nav-dd {
display: none;
}

#main-nav .main-nav-item-active .main-nav-dd {
display: block;
}

Let’s use the active class to style the active tab:

#main-nav .main-nav-item-active .main-nav-tab {
background-color: #FFF;
color: #f60;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}

Here, we’ve changed the background and text colors and rounded the top corners (in supported browsers).

Positioning the Dropdown


Now the basic mouse interaction has been built and the dropdown displays on mouseover. Unfortunately, it is still not positioned correctly under each tab, so let’s add some more code to our hover events:

$(function() {
var $mainNav = $('#main-nav');

$mainNav.children('.main-nav-item').hover(function(ev) {
var $this = $(this),
$dd = $this.find('.main-nav-dd');

// get the left position of this tab
var leftPos = $this.find('.main-nav-tab').position().left;

// position the dropdown

$dd.css('left', leftPos);

// show the dropdown
$this.addClass('main-nav-item-active');
}, function(ev) {

// hide the dropdown
$(this).removeClass('main-nav-item-active');
});
});

Here, we use jQuery’s position() method to get the left offset from the current tab. We then use this value to position the dropdown directly beneath the appropriate tab.

However, with the tabs on the right side, the dropdown menu will end up poking out of the tab area. Besides looking bad, this could lead to overflow issues, with portions of the dropdown falling outside of the browser window.

Let’s fix the positioning with some JavaScript:

$(function() {
var $mainNav = $('#main-nav'),
navWidth = $mainNav.width();

$mainNav.children('.main-nav-item').hover(function(ev) {
var $this = $(this),
$dd = $this.find('.main-nav-dd');

// get the left position of this tab
var leftPos = $this.find('.main-nav-tab').position().left;

// get the width of the dropdown
var ddWidth = $dd.width(),
leftMax = navWidth - ddWidth;

// position the dropdown
$dd.css('left', Math.min(leftPos, leftMax) );

// show the dropdown
$this.addClass('main-nav-item-active');
}, function(ev) {

// hide the dropdown
$(this).removeClass('main-nav-item-active');
});
});

Here, we start by finding the overall width of the tab area. Because recalculating the width for each tab is not necessary, we can define it outside of our hover listener.

Next, we find the width of the dropdown and determine the maximum left value, which is the overall tab width minus the width of the dropdown.

Finally, instead of always positioning the dropdown directly beneath the tab, we use the Math.min() method to pick the lowest between the tab offset and the maximum left value.

Thus, we confine the dropdown to the area beneath the tabs and avoid any content issues.

Other Approaches


While this script is fully functional, we could still improve the user experience. Currently, when the user mouses away from the dropdown, the menu hides immediately. You could build a delay using setTimeout() to ensure that the dropdown remains visible when the user mouses away and then quickly mouses back. This creates a better experience, because it avoids hiding the dropdown during accidental movements.

If you’d rather avoid setTimeout(), you could also look into the hoverIntent jQuery plug-in, which makes fine-tuned control over mouse actions much easier.

Besides improving the user experience, you could also avoid jQuery altogether in all browsers except IE6.

Instead of using jQuery’s hover() listener, we could use the CSS pseudo-class :hover to hide and show the dropdown.

One downside with the CSS-only solution is that you can’t build a delay for the :hover pseudo-class.

Also, you will have to position the dropdown manually under each tab to avoid the overflow issues. Alternatively, if you aren’t concerned with overflow issues, you could attach position: relative to each list item and avoid setting any positions manually.

Finally, if you’re supporting IE6, make sure to include the script above as a backup for IE6 (but don’t include it for other browsers).




4. Animated Slideshow Navigation


Animated-slideshow-navigation in Five Useful Interactive CSS/jQuery Techniques Deconstructed

There are a lot of JavaScript slideshow techniques, but the animated navigation on McKinney is a fresh, subtle approach.

Basic jQuery Slideshow



Let’s build something similar. We’ll start with some mark-up for a basic slideshow:

<div id="slideshow">
<div id="slideshow-reel">
<div class="slide">
<h1>Slide 1</h1>
</div>

<div class="slide">
<h1>Slide 2</h1>
</div>

<div class="slide">
<h1>Slide 3</h1>
</div>

<div class="slide">
<h1>Slide 4</h1>
</div>

<div class="slide">
<h1>Slide 5</h1>
</div>

<div class="slide">
<h1>Slide 6</h1>
</div>
</div>
</div>

Here we’ve set up six slides, which can be filled with any content we need. Let’s set up some CSS to display the slides as a horizontal reel:

#slideshow {
width: 900px;
height: 500px;
overflow: hidden;
position: relative;
}

#slideshow-reel {
width: 5400px;
height: 450px;
position: absolute;
top: 0;
left: 0;
}

#slideshow-reel .slide {
width: 900px;
height: 450px;
float: left;
background-color: gray;
}

Here, we’ve defined the dimensions of the slideshow, along with overflow: hidden to hide the other slides in the reel. We’ve also defined the dimensions of the reel: with six slides at 900 pixels each, it is 5400 pixels wide. (You could also just set this to a really high number, like 10000 pixels.) Then, we absolutely positioned the reel inside the slideshow (which has position: relative). Finally, we defined the dimensions for all of the individual slides and floated them to the left to fill up our reel.

Basic Slideshow Animation


Now, let’s add some jQuery to animate this slideshow:

$(function() {
function changeSlide( newSlide ) {
// change the currSlide value
currSlide = newSlide;

// make sure the currSlide value is not too low or high
if ( currSlide > maxSlide ) currSlide = 0;
else if ( currSlide < 0 ) currSlide = maxSlide;

// animate the slide reel
$slideReel.animate({
left : currSlide * -900
}, 400, 'swing', function() {
// set new timeout if active
if ( activeSlideshow ) slideTimeout = setTimeout(nextSlide, 1200);
});
}

function nextSlide() {
changeSlide( currSlide + 1 );
}

// define some variables / DOM references
var activeSlideshow = true,
currSlide = 0,
slideTimeout,
$slideshow = $('#slideshow'),
$slideReel = $slideshow.find('#slideshow-reel'),
maxSlide = $slideReel.children().length - 1;

// start the animation
slideTimeout = setTimeout(nextSlide, 1200);
});

Here, we’ve started by creating the function changeSlide(), which animates the slide reel. This function accepts an index for the next slide to show, and it checks to make sure that the value isn't too high or low to be in the reel.

Next, it animates the slide reel to the appropriate position, and then finishes by setting a new timeout to trigger the next iteration.

Finally, we’ve built the function nextSlide(), which simply triggers changeSlide() to show the next slide in the reel. This simple function is just a shortcut to be used with setTimeout().

The Left and Right Navigation


Next, let's set up the left and right arrows in the slideshow, starting with the mark-up:

<a href="#" id="slideshow-prev"></a>
<a href="#" id="slideshow-next"></a>

For simplicity's sake, we've added the mark-up to the HTML source. Appending it to the jQuery is often a better approach, to ensure that the controls appear only when they are usable.

Let's style these arrows with CSS:

#slideshow-prev, #slideshow-next {
display: block;
position: absolute;
top: 190px;
width: 0;
height: 0;
border-style: solid;
border-width: 28px 21px;
border-color: transparent;
outline: none;
}

#slideshow-prev:hover, #slideshow-next:hover {
opacity: .5;
filter: alpha(opacity=50);
-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=50)';
}

#slideshow-prev {
left: 0;
border-right-color: #fff;
}

#slideshow-next {
right: 0;
border-left-color: #fff;
}

We’ve positioned the arrows absolutely within the slideshow frame and added an opacity change on hover. In our example, we’ve used a CSS triangle trick to style the arrows with straight CSS, but feel free to use an image if you want richer graphics.

Finally, let's build the required interaction into our JavaScript:

$(function() {
function changeSlide( newSlide ) {
// cancel any timeout
clearTimeout( slideTimeout );

// change the currSlide value
currSlide = newSlide;

// make sure the currSlide value is not too low or high
if ( currSlide > maxSlide ) currSlide = 0;
else if ( currSlide < 0 ) currSlide = maxSlide;

// animate the slide reel
$slideReel.animate({
left : currSlide * -900
}, 400, 'swing', function() {
// hide / show the arrows depending on which frame it's on
if ( currSlide == 0 ) $slidePrevNav.hide();
else $slidePrevNav.show();

if ( currSlide == maxSlide ) $slideNextNav.hide();
else $slideNexNav.show();

// set new timeout if active
if ( activeSlideshow ) slideTimeout = setTimeout(nextSlide, 1200);
});

// animate the navigation indicator
$activeNavItem.animate({
left : currSlide * 150
}, 400, 'swing');
}

function nextSlide() {
changeSlide( currSlide + 1 );
}

// define some variables / DOM references
var activeSlideshow = true,
currSlide = 0,
slideTimeout,
$slideshow = $('#slideshow'),
$slideReel = $slideshow.find('#slideshow-reel'),
maxSlide = $slideReel.children().length - 1,
$slidePrevNav = $slideshow.find('#slideshow-prev'),
$slideNextNav = $slideshow.find('#slideshow-next');

// set navigation click events

// left arrow
$slidePrevNav.click(function(ev) {
ev.preventDefault();

activeSlideshow = false;

changeSlide( currSlide - 1 );
});

// right arrow
$slideNextNav.click(function(ev) {
ev.preventDefault();

activeSlideshow = false;

changeSlide( currSlide + 1 );
});

// start the animation
slideTimeout = setTimeout(nextSlide, 1200);
});

Here, we've added quite a bit of new interaction. First, look at the bottom of this script, where we've added click event listeners to both of our navigational items.

In these functions, we have first set activeSlideshow to false, which disables the automatic animation of the reel. This provides a better user experience by allowing the user to control the reel manually. Then, we trigger either the previous or next slide using changeSlide(). Next, in the changeSlide() function, we've added a clearTimeout(). This works in conjunction with the activeSlideshow value, cancelling any hanging iteration from a setTimeout.

Finally, in the callback of the animate() function, we've added some code to hide and show the arrow navigation. This hides the left arrow when the slideshow is showing the left-most slide, and vice versa.

Animating the Bottom Navigation


The basic slideshow works with the previous and next arrows. Let's take it to the next level by adding the animated navigation. Please note that I am using a more complex markup because it avoids the use of images and is ultimately simpler. It would have to use three background images otherwise — one for the center sections and one for each cap to allow the clickable areas to be larger). However, you could clean up the bottom navigation with a background-image.

Here is the jQuery code for animation:

$(function() {
function changeSlide( newSlide ) {
// cancel any timeout
clearTimeout( slideTimeout );

// change the currSlide value
currSlide = newSlide;

// make sure the currSlide value is not too low or high
if ( currSlide > maxSlide ) currSlide = 0;
else if ( currSlide < 0 ) currSlide = maxSlide;

// animate the slide reel
$slideReel.animate({
left : currSlide * -900
}, 400, 'swing', function() {
// hide / show the arrows depending on which frame it's on
if ( currSlide == 0 ) $slidePrevNav.hide();
else $slidePrevNav.show();

if ( currSlide == maxSlide ) $slideNextNav.hide();
else $slideNextNav.show();

// set new timeout if active
if ( activeSlideshow ) slideTimeout = setTimeout(nextSlide, 1200);
});

// animate the navigation indicator
$activeNavItem.animate({
left : currSlide * 150
}, 400, 'swing');
}

function nextSlide() {
changeSlide( currSlide + 1 );
}

// define some variables / DOM references
var activeSlideshow = true,
currSlide = 0,
slideTimeout,
$slideshow = $('#slideshow'),
$slideReel = $slideshow.find('#slideshow-reel'),
maxSlide = $slideReel.children().length - 1,
$slidePrevNav = $slideshow.find('#slideshow-prev'),
$slideNextNav = $slideshow.find('#slideshow-next'),
$activeNavItem = $slideshow.find('#active-nav-item');

// set navigation click events

// left arrow
$slidePrevNav.click(function(ev) {
ev.preventDefault();

activeSlideshow = false;

changeSlide( currSlide - 1 );
});

// right arrow
$slideNextNav.click(function(ev) {
ev.preventDefault();

activeSlideshow = false;

changeSlide( currSlide + 1 );
});

// main navigation
$slideshow.find('#slideshow-nav a.nav-item').click(function(ev) {
ev.preventDefault();

activeSlideshow = false;

changeSlide( $(this).index() );
});

// start the animation
slideTimeout = setTimeout(nextSlide, 1200);
});

We've added a couple of things to our script.

First, we've included a second animation in changeSlide(), this time to animate the active indicator in the navigation. This animate() is basically the same as the one we built for the reel, the main difference being that we want to move it only 150px per slide.

Finally, we added a click event listener to the items in the bottom navigation. Similar to the arrow navigation, we start by disabling the automatic animation, setting activeSlideshow to false. Next, we trigger changeSlide(), passing in the index of whichever slide was clicked, which is easy to determine using jQuery's index() method.

Now the slideshow navigation animation is complete and ready to impress your visitors.




5. Animated Icons


Animated-icons-on-css-tricks in Five Useful Interactive CSS/jQuery Techniques Deconstructed

CSS-Tricks has a simple but elegant effect in its footer when the user mouses over various buttons. Besides the color changing and an icon being added, the effect is animated in browsers that support transition, making the icon appear to slide into place.


Let's create a similar effect, starting with some mark-up:

<a href="#" class="hover-panel">
<h3>Panel Title</h3>

<p>Additional information about the panel goes in a paragraph here</p>
</a>

One thing to note about this mark-up is that it has block elements nested in an <a> element, which makes sense semantically, but it's valid only if you're using the HTML5 doc type.

Styling the Buttons


Let's set up some basic CSS to style the block in its natural (non-hovered) state:

.hover-panel {
background-color: #E6E2DF;
color: #B2AAA4;
float: left;
height: 130px;
width: 262px;
margin: 0 10px 10px 0;
padding: 15px;
}

.hover-panel h3 {
font-family: tandelle-1, tandelle-2, Impact, Sans-serif, sans;
font-size: 38px;
line-height: 1;
margin: 0 0 10px;
text-transform: uppercase;
}

.hover-panel p {
font-size: 12px;
width: 65%;
}

Now let's add a static hover effect to change some of the colors and add a drop shadow:

.hover-panel:hover {
background-color: #237ABE;
}

.hover-panel:hover h3 {
color: #FFF;
text-shadow: rgba(0, 0, 0, 0.398438) 0px 0px 4px;
}

.hover-panel:hover p {
color: #FFF:
}

Finally, let's add a background image that pops into place on hover:

.hover-panel {
background-image: url(hover-panel-icon.png);
background-position: 292px 10px;
background-repeat: no-repeat;
}

.hover-panel:hover {
background-position: 180px 10px;
}

Here, we've added a few important styles to accomplish the hover effect. First, we've attached the background image to our .hover-panel. This is normally positioned outside of the button, but on mouseover, it is placed correctly. Also, note that we've placed it off to the right side of the panel, so that when we apply the transition animation, the icon will slide in from the right.

Animating the Transition


Finally, let's add the transition:

.hover-panel {
-moz-transition: all 0.2s ease; /* FF3.7+ */
-o-transition: all 0.2s ease; /* Opera 10.5 */
-webkit-transition: all 0.2s ease; /* Saf3.2+, Chrome */
transition: all 0.2s ease;
}

The transition effect triggers the animation of the background image. Because we've flagged it to apply to all attributes, the transition will also be applied to the background-color change that we applied above.

Although this works in most modern browsers, it will not work in IE9. But even in unsupported browsers, the user will see the color change and icon; they just won't see the animation effect.

On most websites, this enhancement wouldn't be necessary for all users. But if support is a priority, look into this jQuery back-up.

Finally, let's bring all of the styles together:

.hover-panel {
background-color: #E6E2DF;
background-image: url(hover-panel-icon.png);
background-position: 292px 10px;
background-repeat: no-repeat;
color: #B2AAA4;
display: block;
float: left;
height: 130px;
width: 262px;
margin: 0 10px 10px 0;
padding: 15px;
-moz-transition: all 0.2s ease; /* FF3.7+ */
-o-transition: all 0.2s ease; /* Opera 10.5 */
-webkit-transition: all 0.2s ease; /* Saf3.2+, Chrome */
transition: all 0.2s ease;
}

.hover-panel h3 {
font-family: tandelle-1, tandelle-2, Impact, Sans-serif, sans;
font-size: 38px;
line-height: 1;
margin: 0 0 10px;
text-transform: uppercase;
}

.hover-panel p {
font-size: 12px;
width: 65%;
}

.hover-panel:hover {
background-color: #237ABE;
background-position: 180px 10px;
}

.hover-panel:hover h3 {
color: #FFF;
text-shadow: rgba(0, 0, 0, 0.398438) 0px 0px 4px;
}

.hover-panel:hover p {
color: #FFF:
}


Final Thoughts


In this article, we've walked through a variety of interactive techniques that can add a bit of style and creativity to your website. Used correctly, techniques like these enhance websites, creating a more engaging and memorable user experience. But be subtle with the interactivity, ensuring that the bells and whistles do not get in the way of the website's primary function, which is to providing meaningful content.

What do you think of the techniques presented here? Do you know of any ways to improve these scripts? What are some other interactive techniques that you've seen around the Web?

(al)




© Jon Raasch for Smashing Magazine, 2011. |
Permalink |
Post a comment |
Smashing Shop |
Smashing Network |
About Us



Post tags:


"

5 Features of CSS3 You Can Use Today

5 Features of CSS3 You Can Use Today: "
A few days ago, the CSS 2.1 specification finally achieved W3C recommendation status. After many years of hard work, CSS 2.1 is now so well supported that upgrading the spec to recommendation status is mostly a formality. On the same day, the CSS 3 Color Module also become a recommendation. All of this is exciting news, because it means that the web is well on its way to a future filled with glorious CSS 3.

While CSS 2.1 now enjoys extremely broad interoperability, the same is not currently true for CSS 3. While the W3C and browser vendors work furiously to build our tomorrow, here are five CSS 3 features that you can start using in your sites today.

Border Radii


The border-radius property allows you to ostensibly curve the corners of an element. Previously, this was a rather tricky thing to do, involving the use of images and extra markup. Now, you can create a curved box like the one you see below.

A rectangle with curved corners.

The Code


To apply a border radius to an element, simply select the element in your CSS code and apply the border-radius property. Then, give the property an absolute or percentage value. The higher the value, the more curvy your corners will appear. To make this work in some browsers, you will need to include what are called vendor prefixes. These are necessary to protect future compatibility, should the W3C decide to change a CSS 3 property.


.myElement {

/* A few vendor-prefixed versions of the property... */
-webkit-border-radius: 20px;
-moz-border-radius: 20px;

/* ...and the 'real' property last. */
border-radius: 20px;

}


Browser Compatibility


Provided that you include the proper vendor prefixes, the border-radius property works in just about every modern browser, including Firefox, Safari, Opera, and Google Chrome. It now also works in Internet Explorer, starting with version 9. Even if the client browser doesn’t support this property, it just means that they will see squared-off corners instead of smooth curves. Remember, webpages don’t need to look exactly the same in every browser; slight cosmetic variations like this are acceptable.

New Color Models


CSS 3 comes with several new properties like border-radius, but it also comes with new units as well. CSS 2.1 offers several different ways to declare colors, such as the hexadecimal format or the named color format. Additionally, CSS 2.1 allowed colors to be specified using a special rgb() function, and CSS 3 builds upon this with rgba(), hsl(), and hsla(). While hsl() allows you to specify color using hue, saturation, and lightness (rather than red, green, and blue colors), it is the a that’s more interesting. In the rgba() and hsla() functions, the a stands for "alpha" and it allows you to adjust the opacity of the color.

A bright orange colored rectangle, with some very slight transparency added..

The Code


To utilize one of the new color models, simply use them anywhere you might use a color. One example of this is of course the background property, which can set the background of an element to a color. To use the rgba() function, supply the red, green, and blue values, separated by commas. These should be numbers between 0 and 255, or percentages. Finally, add in the alpha value, which should be a number between 0 and 1, inclusive. The higher the number, the more opaque the color will appear, with 1 being completely opaque. These new color values do not require the use of any special vendor prefixes.


.myElement {

/* A bright orange color, with some very slight transparency added. */
background: rgba(255, 128, 0, 0.7);

}


The hsla() color model also takes four values. The first value is the hue, and is just an integer. The next two values are for the saturation and lightness, and these should be percentages. Finally, the alpha value functions the same as with the rgba() function, and should be a number between 0 and 1, inclusive.


.myElement {

/* A solid blue color, with the transparency cut in half. */
color: hsla(240, 100%, 50%, 0.5) }

}


Browser Compatibility


These new color models will work in every modern browser. Internet Explorer began supporting CSS 3 color models starting with version 9, and because colors can be more than just aesthetic enhancements, it’s important to make sure they work properly in the majority of clients. So then, what if a browser doesn’t support one of these new color models? As a fallback, you can try something like this:


.myElement {

color: rgb(255, 0, 0);
color: rgba(255, 0, 0, 0.9);

}


Remember, the rgb() function is a part of CSS 2.1, which is already widely supported. If a browser is capable of utilizing the rgba() function, then the second declaration will override the first. If not, then the second declaration will simply be ignored. The only thing missing in this case will be the slight transparency. As I mentioned previously, slight cosmetic variations like this are acceptable.

Box Shadows


The box-shadow property makes it easy to create shadows underneath elements. Prior to CSS 3, this effect was somewhat challenging to produce and almost always required the use of images.

A brightly colored rectangle with a shadow underneath.

The Code


The box-shadow property takes four values. The first two values are the X and Y offsets, and they determine the angle of the light. The third value is the blur radius. The higher the value, the fuzzier the shadow will appear. These first three properties can be absolute or relative values. The last value is a color. Of course, you could use a hexadecimal color, but the box-shadow property is much more interesting when combined with the new color models in CSS 3. Using the rgba() color model allows the opacity of the shadow to be adjusted, making it appear as though the shadow is naturally blending with the background. Similar to the border-radius property, this property also requires the usage of vendor prefixes.


.myElement {

/* A few vendor-prefixed versions of the property... */
-webkit-box-shadow: 5px 5px 5px rgba(0,0,0,0.7);
-moz-box-shadow: 5px 5px 5px rgba(0,0,0,0.7);

/* ...and the 'real' property last. */
box-shadow: 5px 5px 5px rgba(0,0,0,0.7);

}


Browser Compatibility


As is the case with the border-radius property, this CSS 3 feature works in all modern browsers and will work in Internet Explorer 9 and up.

Fonts


Computers have been capable of displaying multiple fonts for several decades now, so it might seem odd that fonts are only just now becoming standardized on the web. However, disagreement on file formats along with complex font licensing issues have turned this into quite a difficult challenge to overcome. Fortunately, CSS 3 has put the spotlight back on web fonts, and the web is rapidly moving into a multi-font future.

A special font that spells out the words 'Lorem Ipsum'.

The Code


Applying various fonts to blocks of text is nothing new. However, the ability to include new font faces is indeed new, where as before, we were limited to the browser defaults. To include a new font, download the font file that you’d like to include, and then use the @font-face rule to specify a name for the font along with a file path. After that, you can use the font as you normally would.


@font-face {

/* Pick a name for your font. */
font-family: orbitron;

/* Then, include the file path to the font file. */
src: url('orbitron-light.otf');

}

.myElement {

/* Finally, apply the new font to an element, with some fallbacks. */
font-family: orbitron, verdana, sans-serif;

}


Browser Compatibility


This seems simple enough, and indeed, the @font-face rule works in every browser going all the way back to early versions of Internet Explorer. Including fonts isn’t quite that straightforward due to a few lingering file format compatibility issues, but fortunately, several font services have greatly simplified the process and abstracted away these problems. My favorite font service is Google Web Fonts, and I highly recommend you check it out. You can pick any fully licensed font for free, and then all you have to do is include a CSS file from Google’s fast content delivery network. Once the external CSS file has been included, the new font is available to use in other CSS documents that follow.

Opacity


With CSS 3, you can easily adjust the transparency of an element by using the opacity property. Using CSS 2.1, effects like this were tricky to achieve and in some cases, impossible.

A slightly transparent rectangle layered on top of a brightly colored rectangle.

The Code


To dial down the opacity of an element, simply apply the opacity property. Then, give it a value between 0 and 1, inclusive.


.myElement {

/* This will make the element 70% opaque, or 30% transparent. */
opacity: 0.7

}


Browser Compatibility


As you might expect, this property enjoys broad support from every modern browser. opacity will work in Internet Explorer 9 and up, but to accomodate older versions of Internet Explorer, this property should be used for aesthetic enhancements only.


"

sábado, 11 de junio de 2011

Duplicate DeSandro’s CSS Effect

Duplicate DeSandro’s CSS Effect: "
I recently stumbled upon David DeSandro’s website when I saw a tweet stating that someone had stolen/hotlinked his website design and code, and he decided to do the only logical thing to retaliate: use some simple JavaScript goodness to inject unicorns into their page. A brilliant idea, if I may say so myself (and I may). David’s design is simplistic but features a few classy CSS effects, one of the most impressive being the footer “made this” animation. Let me show you how David accomplished this effect.

The HTML

The system will consist of a wrapper (though it’s not necessarily needed), an link, and a series of SPAN tags:
<div id="animationWrapper">
<a href="/">
<span class="span1">David</span>
<span class="span2">J. Walsh</span>
<span class="span3">Arsenal</span>
<span class="span4">Legend</span>
</a>
</div>
You’ll understand the need for SPAN tags with separate classes when you see the CSS.

The CSS

There are a good amount of styles but the most important are applied to the SPAN elements:
/* entire wrapper */
#animationWrapper {
width:300px;
font-family:'proxima-nova-1','proxima-nova-2','Helvetica Neue','Arial',sans-serif;
background:#222;
padding:40px;
}

/* link which encapsulates SPANs */
#animationWrapper a {
font-weight: 800;
text-transform: uppercase;
font-size: 42px;
line-height: 0.9em;
margin-bottom: 10px;
display: block;
position: relative;
color: #E58;
text-decoration: none
}

/* span and a - 'workers' */
#animationWrapper a, #animationWrapper span {
-webkit-transition: all 0.12s ease-out;
-moz-transition: all 0.12s ease-out;
-o-transition: all 0.12s ease-out;
-ms-transition: all 0.12s ease-out;
transition: all 0.12s ease-out;
}

#animationWrapper span {
display: block;
color: #555;
text-shadow: 1px 1px black, 2px 2px black, 3px 3px black, 4px 4px black, 5px 5px black, 6px 6px black, 7px 7px black, 8px 8px black;
}

/* special size for the first item */
#animationWrapper .span1 {
font-size: 76px;
line-height: 0.8em;
}

#animationWrapper a:hover {
color: #fff ;
top: -3px;
left: -3px;
}

/* all spans become white */
#animationWrapper a:hover span {
color:#fff;
}

/* different colors for each SPAN */
#animationWrapper a:hover .span1 {
text-shadow: 1px 1px #58E, 2px 2px #58E, 3px 3px #58E, 4px 4px #58E, 5px 5px #58E, 6px 6px #58E, 7px 7px #58E, 8px 8px #58E, 9px 9px #58E, 10px 10px #58E, 11px 11px #58E;
}

#animationWrapper a:hover .span2 {
text-shadow: 1px 1px #F90, 2px 2px #F90, 3px 3px #F90, 4px 4px #F90, 5px 5px #F90, 6px 6px #F90, 7px 7px #F90, 8px 8px #F90, 9px 9px #F90, 10px 10px #F90, 11px 11px #F90;
}

#animationWrapper a:hover .span3 {
text-shadow: 1px 1px #3C7, 2px 2px #3C7, 3px 3px #3C7, 4px 4px #3C7, 5px 5px #3C7, 6px 6px #3C7, 7px 7px #3C7, 8px 8px #3C7, 9px 9px #3C7, 10px 10px #3C7, 11px 11px #3C7;
}

#animationWrapper a:hover .span4 {
text-shadow: 1px 1px #E58, 2px 2px #E58, 3px 3px #E58, 4px 4px #E58, 5px 5px #E58, 6px 6px #E58, 7px 7px #E58, 8px 8px #E58, 9px 9px #E58, 10px 10px #E58, 11px 11px #E58;
}
The plain state SPAN receives a base text-shadow value and also defines the transition properties which will be played upon hover. Each SPAN contains its own class which controls its text-shadow color and width during hover. The hover state then enacts those text-shadow and color properties.
Well done to David for his simple but classy CSS effect. If we’re being honest, those are the best kind.
Duplicate DeSandro’s CSS Effect is a post from: David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.
Related posts:
  1. Duplicate the jQuery Homepage Tooltips
  2. Duplicate the jQuery Homepage Tooltips Using MooTools
  3. Duplicate the jQuery Homepage Tooltips Using Dojo
  4. Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo JavaScript
  5. Dress Up Your Select Elements with FauxSelect
"

miércoles, 8 de junio de 2011

Amazing CSS3 techniques you should know

Amazing CSS3 techniques you should know: "

Color animate any shape with CSS3 and a PNG


Let’s start this compilation with an interesting effect created using only CSS3: A png image with a changing background. The background is using CSS3 transitions. Not the kind of effect you’ll put on your website, but definitely an interesting demo of what CSS3 can do.
View source: http://jsfiddle.net/chriscoyier/vhKhT/

Create adaptable layout using CSS3 media queries


CSS3 media queries allow you to adapt a web layout to the browser width. Which means that you can easily create an adaptable layout that fits both big displays and mobile devices. You probably already checked my article on that subject, so I’ve picked another informative tutorial written by webdesigner Nick La. A technique any web developer should know!
View tutorial: http://webdesignerwall.com/tutorials/adaptive-mobile-design-with-css3-media-queries

Dim entire page when certain link is rolled over, css way


Very cool for web apps: Once a particular link is rolled over, the rest of the page is dimmed. This technique may also be a starting point for other great experiments.
View source: http://jsfiddle.net/chriscoyier/pVsKe/1/

Clipping text with CSS3 text-overflow


text-overflow is a new CSS3 property which allows you to define how to handle a text which is bigger than its container. This example will show you anything you need to know about this property. Unfortunely, as I’m writing this post text-overflow is only supported by Opera and IE9.
View source: http://www.456bereastreet.com/archive/201105/clipping_text_with_css3_text-overflow/

Full Browser Width Bars


Another goldie from Chris Coyier: In this tutorial, he’ll teach you how to create full browser width bars easily.
View source: http://css-tricks.com/examples/FullBrowserWidthBars/

CSS Mask-Image & Text


A great text effect using CSS3 and mask images. Unfortunately, the effect is not supported by some browsers, but it degrades gracefully. This effect will probably be very popular when CSS3 will be fully supported by all major browsers.
View source: http://trentwalton.com/2011/05/19/mask-image-text/

Image slider with CSS3 transitions


Who’s never heard of JavaScript sliders, such as NivoSlider? That kind of effect is very popular for the past two or three years. With the new CSS3 animations, it is now possible to enhance transitions between images. This tool, called Flux Slider, supports either jQuery or Zepto.js. It works on any browser supporting CSS3 transitions.
View source: http://blog.joelambert.co.uk/2011/05/05/flux-slider-css3-animation-based-image-transitions/

Flared Borders with CSS


Remember that time when you had to create images just to display a box with rounded corners? Thanks to the border-radius, this painful process is no longer needed. This very cool tutorial will show you how to create an element that flares into another using only CSS. The whole code degrades gracefully in older browsers.
View source: http://orderedlist.com/blog/articles/flared-borders-with-css/
"

miércoles, 18 de mayo de 2011

CSS3 tooltips

CSS3 tooltips: "
If your icon or button has insufficient text or none at all, or it just needs some additional explanation, then you surely need a tooltip for it. Why’s that? Because, as they have proved till now, tooltips can help you improve your website usability.

Having said that, in this article you’ll learn how to create your own CSS tooltips: no images, no javascript.





View demo

“Do I need CSS tooltips?”


The HTML title attribute is the default tooltip you can use. But, default tooltips can’t be styled. If you want a cool tooltip, one that you can style it as you wish, then a custom CSS tooltip is the solution.

How is made


The method might be familiar to you, a relative positioned element who wraps an absolute positioned one. With this article I’m not trying to reinvent the wheel, I’m just showing you how to create some cool CSS3 tooltips.

Below you can see the proper tooltip structure, note the two pointers (made using :before and :after pseudo-elements ) who overlap:



How the “bordered” pointer is made

Here are the ingredients that were used to create the tooltips:


HTML


<a href="#" class="tooltip">
your text
<span>Your tooltip description</span>
</a>

Why an anchor?


Just for compatibility reasons. IE6 has a problem with the :hover pseudo-class used with other elements than anchor.

If you want to use these tooltips, and anchors are not an option for you, then you can use this to trigger the tooltip for IE6:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(function() {
if ($.browser.msie && $.browser.version.substr(0,1)<7)
{
$('.tooltip').mouseover(function(){
$(this).children('span').show();
}).mouseout(function(){
$(this).children('span').hide();
})
}
});
</script>

CSS


.tooltip
{
position: relative;
background: #eaeaea;
cursor: help;
display: inline-block;
text-decoration: none;
color: #222;
outline: none;
}

.tooltip span
{
visibility: hidden;
position: absolute;
bottom: 30px;
left: 50%;
z-index: 999;
width: 230px;
margin-left: -127px;
padding: 10px;
border: 2px solid #ccc;
opacity: .9;
background-color: #ddd;
background-image: -webkit-linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
background-image: -moz-linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
background-image: -ms-linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
background-image: -o-linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
background-image: linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,0));
-moz-border-radius: 4px;
border-radius: 4px;
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.5) inset;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.5) inset;
box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.5) inset;
text-shadow: 0 1px 0 rgba(255,255,255,.4);
}

.tooltip:hover
{
border: 0; /* IE6 fix */
}

.tooltip:hover span
{
visibility: visible;
}

.tooltip span:before,
.tooltip span:after
{
content: '';
position: absolute;
z-index: 1000;
bottom: -7px;
left: 50%;
margin-left: -8px;
border-top: 8px solid #ddd;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 0;
}

.tooltip span:before
{
border-top-color: #ccc;
bottom: -8px;
}

View demo

Browser support


This is a cross-browser solution, it works also on browsers like IE6 and IE7. Although, it looks quite different as we're talking here about progressive enhancement.

"

martes, 17 de mayo de 2011

CSS3 drop shadow generator

CSS3 drop shadow generator: "
A fantastic CSS shadow generator free for use and with tons of features, including more than 8 shadow styles, opacity, blur and position handlers, real-time preview of both design and source code.
"

Animated Skills Diagram with Raphaël

Animated Skills Diagram with Raphaël: "

View demo Download source
In this tutorial we will show you how to create a diagram using Raphaël – a small JavaScript library that is great for working with vector graphics. The idea is very simple: we will draw some arcs using mathematical functions and we’ll be displaying a skill percentage in a main circle when we hover over those arcs.
Let’s start with the markup.

The Markup

The HTML structure is going to consist of a main container with the class ‘get’. This container stores all data that we need to draw the arcs. Then we create a new div element with the id ‘diagram’ which will be the container for the arcs:
<div id="diagram"></div>
<div class="get">
<div class="arc">
<span class="text">jQuery</span>
<input type="hidden" class="percent" value="95" />
<input type="hidden" class="color" value="#97BE0D" />
</div>
<div class="arc">

<span class="text">CSS3</span>
<input type="hidden" class="percent" value="90" />
<input type="hidden" class="color" value="#D84F5F" />
</div>
<div class="arc">
<span class="text">HTML5</span>
<input type="hidden" class="percent" value="80" />
<input type="hidden" class="color" value="#88B8E6" />

</div>
<div class="arc">
<span class="text">PHP</span>
<input type="hidden" class="percent" value="53" />
<input type="hidden" class="color" value="#BEDBE9" />
</div>
<div class="arc">
<span class="text">MySQL</span>
<input type="hidden" class="percent" value="45" />
<input type="hidden" class="color" value="#EDEBEE" />
</div>
</div>

The CSS

In the CSS we will only do two things: hide the elements with the class ‘get’ and set the width and height of the div with the id ‘diagram’:
.get {
display:none;
}

#diagram {
float:left;
width:600px;
height:600px;
}

The JavaScript

The main idea is to first create a new Raphael object (variable ‘r’) and draw our first circle with a radius that we specify in ‘rad’.
Then we create a new circle in the Raphael object. We center the circle (x: 300px and y: 300px) and we add some text to it.
var o = {
init: function(){
this.diagram();
},
random: function(l, u){
return Math.floor((Math.random()*(u-l+1))+l);
},
diagram: function(){
var r = Raphael('diagram', 600, 600),
rad = 73;

r.circle(300, 300, 85).attr({ stroke: 'none', fill: '#193340' });

var title = r.text(300, 300, 'Skills').attr({
font: '20px Arial',
fill: '#fff'
}).toFront();

}
}
Now, let’s go one step further.
We’ll extend the Raphael object with some custom attributes:
  • alpha – angle of the arc
  • random – random number from the specified range
  • sx, sy – start drawing from this point
  • x, y – end drawing at this point
  • path
var o = {
init: function(){
this.diagram();
},
random: function(l, u){
return Math.floor((Math.random()*(u-l+1))+l);
},
diagram: function(){
var r = Raphael('diagram', 600, 600),
rad = 73;

r.circle(300, 300, 85).attr({ stroke: 'none', fill: '#193340' });

var title = r.text(300, 300, 'Skills').attr({
font: '20px Arial',
fill: '#fff'
}).toFront();

r.customAttributes.arc = function(value, color, rad){
var v = 3.6*value,
alpha = v == 360 ? 359.99 : v,
random = o.random(91, 240),
a = (random-alpha) * Math.PI/180,
b = random * Math.PI/180,
sx = 300 + rad * Math.cos(b),
sy = 300 - rad * Math.sin(b),
x = 300 + rad * Math.cos(a),
y = 300 - rad * Math.sin(a),
path = [['M', sx, sy], ['A', rad, rad, 0, +(alpha > 180), 1, x, y]];
return { path: path, stroke: color }
}

$('.get').find('.arc').each(function(i){
var t = $(this),
color = t.find('.color').val(),
value = t.find('.percent').val(),
text = t.find('.text').text();

rad += 30;
var z = r.path().attr({ arc: [value, color, rad], 'stroke-width': 26 });

z.mouseover(function(){
this.animate({ 'stroke-width': 50, opacity: .75 }, 1000, 'elastic');
if(Raphael.type != 'VML') //solves IE problem
this.toFront();
title.animate({ opacity: 0 }, 500, '>', function(){
this.attr({ text: text + '\n' + value + '%' }).animate({ opacity: 1 }, 500, '<');
});
}).mouseout(function(){
this.animate({ 'stroke-width': 26, opacity: 1 }, 1000, 'elastic');
});
});
}
}
Then we’ll retrieve all the data needed, such as the percentage value, the color of the arc and the text. We increase the radius value for each arc and finally create a new arc path.
In the last step we are adding some animations on hover. When the mouse will be over the arc the title (which is placed in the main circle) is changing. Also, we’ll make the arc a little bit bigger.

Conclusion

In today’s tutorial you’ve learned some first steps on how to use Raphaël. It is a powerful library and you can do a lot of great stuff with it. Visit the Raphaël website for more examples.
View demoDownload source
Share and Enjoy:Diggdel.icio.usFacebookLinkedInRedditRSSTwitterGoogle BookmarksStumbleUponTechnoratiDZoneemailblogmarksDesign FloatDiigoFriendFeedGoogle BuzzIdenti.caMisterWongNewsVinePing.fmPlurkPosterousSlashdotSuggest to Techmeme via TwitterTumblr

"