redeyeopsredeyeops

expanding the nature of the web

path-ani

December 17, 2011
by Jacob Lowe
1 Comment

Path App Fly-out Menu using CSS3 & jQuery

Hey Bloggies,

So I’m a huge app consumer and love to see what new apps have to offer. I gladly downloaded an app called Path which is a sudo social network. I am a huge sucker for great ui design so I fell in love. The thing that really stole my focus was the awesome fly-out menu that is in the bottom left corner. This button is the main means of navigation in this app. It had not only some good features but also had smooth animations as well. Me being a noob to application development, googled if it was made in phone gap due to it heavy customization and no it wasn’t. It ‘apparenly’ has too advanced animations.

Me being an avid advocate for HTML 5 felt that the thought of too advanced for HTML 5 felt like a challenge. So I took it upon myself, along with some other in the community, to build this animation on web technologies. Kinda disappointed by other demos, my goal was mobile compliance. So the hacking ensued.

Setup

First the major hurtle was making a layout of the menu look like the one in Path. I was challenged to make the animation so the scale and quanity was not a big issue to me. I decided a larger scale with less buttons could get the point across. Instead of opting in to a nice math battle with sin and cos for the circles I cheated by laying out the buttons on Photoshop.

Once I had some simple parameters for top and left positions I did some minor number crunching to figure in the offset to the center of the buttons because positioning is usually based off the top left.

HTML

<div id="circle-mod">
    <div id="container-circle">
        <div id="button-1" class="btn"></div>
        <div id="button-2" class="btn"></div>
        <div id="button-3" class="btn"></div>
        <div id="button-4" class="btn"></div>
        <div id="button-5" class="btn" ></div>
        <div id="base-button"></div>
    </div>
</div>

Finally after calculating the buttons positions I had end points for each button. I set up my HTML structure (above) and set some CSS for the initial positioning (below) of the buttons. After I the added the end positions with a added class called open. By default the buttons will be in the center of the base button. With a class added the buttons will move to their ending position as open. To make the transition I added the css3 property transition, and of course added vendor prefixes as well.

CSS

/* Move whole container to bottom left corner */
#circle-mod{
    position: absolute;
    bottom: 0;
    left: 10px;
}
/* Make a relative container */
#container-circle {
    position: relative;
    height: 100px;
    width: 100px;
}
/*Create my base button*/
#base-button {
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 50px;
    height: 80px;
    width: 80px;
    background: #ddd;
    /* Some extra styles, add -webkit prefix to work on most mobile browsers */
    box-shadow: 0px 1px 3px rgba(0,0,0,.5);
    padding: 0;
}
/* Generic button and center position */
.btn{
    position: absolute;
    height: 50px;
    width: 50px;
    border-radius: 25px;
    top: 15px;
    left: 15px;
    background: #ccc;
    /* Essential to the animation */
    -webkit-transition: all 250ms;
    -moz-transition: all 250ms;
    -o-transition: all 250ms;
    -ms-transition: all 250ms;
    transition: all 250ms;
    /* Same as above */
    box-shadow: 0px 1px 3px rgba(0,0,0,.5);
}

#button-1.open{
    top: -125px;
    left: 25px;
}

#button-1.open.clicked{
    top: -135px;
    left: 15px;
}

#button-2.open{
    top: -105px;
    left: 80px;
}

#button-3.open{
    top: -75px;
    left: 125px;
}

#button-4.open{
    top: -30px;
    left: 160px;
}

#button-5.open{
    left: 175px;
    top: 25px;
}

Next I needed a way to add apply classes in an order manner so that it would look like a sweeping manner. Javascript, more specifically Jquery, was a simple answer to this. I threw a toggle on the main button which would init a each loop to run through all the buttons. For the asyncronous application of the class to each button. I set a timeout around the add class function. Each timeout fires a little later then the last due to multplying a delay against the index of the btns.

Javascript

// Delay in ms, delayTime for inside set timeout, array of btns
var delay = 40, delayTime, btns = $('.btn');
//Select base button and toggle - click is default
$('#base-button').toggle(function(){
    // Loop through buttons
    btns.each(function(i){
        //Declaring the element
        var ele = $(this);
        //Multiple the delay time by the index of the button
        delayTime = i * delay;
        //Timeout set to delaytime
        window.setTimeout(function(){
            //Add Class open
            ele.addClass('open');
        }, delayTime);
    //Close each loop
    });
//Toggle on next click
}, function(){
    //Closing Loop Next paragraph
})

With the first loop applied I tested the page. Success!. It looked nice and after some minor tweeks to the timing it was nearly perfect.

I felt if I copied my code from the first toggle it would finish the full effect. Nope it looked nice but the animation was off because it looped through the buttons in the reverse order in the actual animation. With jQuery this a simple fix.

//Full code for copy pasters
$(function(){
    //Comment for this section above
    var delay = 40, delayTime, btns = $('.btn');
    $('#base-button').toggle(function(){
        btns.each(function(i){
            var ele = $(this);
            delayTime = i * delay;
            window.setTimeout(function(){
                ele.addClass('open');
            }, delayTime);
        });
    //Now the next toggle
    }, function(){
        //Get reversed array of btns
        $($(btns).get().reverse()).each(function(i){
            //This is the same
            var ele = $(this);
            delayTime = i * delay;
            //ditto
            window.setTimeout(function(){
                //Now let remove the class 'open'
                ele.removeClass('open');
            }, delayTime);
        });
    });
})

If these are done all according to above you should have a fully functional fly-out menu. Now for the demo look at the source code. Most of it is in here but I added alot of extra styles just for look. Also check out the CSS transition timing method put on the buttons for a bit of a ease.

Be a source code treasure hunter on this demo there is alot more mods then in the tutorial, but hopefully you can get the basis of the animation.

notify-preview

November 27, 2011
by Jacob Lowe
0 comments

Notify – A notification jQuery plugin

Recently I have been swamped with work and also giving support for my first jQuery plugin Zoomy. With all the success with Zoomy I have decided to author another plugin. I have been building all kinds of little things here and there so I was thinking what could be useful? So I did a little surfing and found out alot of companies use notifications to alert their uses to some type of event going on with the site or the sites company. So I decided that I wanted to replicate the most common.

This notification was a long bar right at the top of the window. I have a feeling this was a way to sort of make a website look like an IE or Firefox native to the browser notification. So I had a really good feeling that many other people would want something like this as well. First time I really recognized this type of notification was on Google‘s main page. There was a blue notification that had came up that it would prompt asking “Would you like to bookmark Google as your homepage”. Then again I saw Mashable using this same technique telling its readers “Hey Circle us on Google Plus”. Last to mention on Yahoo I noticed the same bar that claimed “We have a New Layout give us your feedback”.

Let them know

First like any jQuery plugin you need to include jQuery, and the file to plugin. Also with this plugin you need to add a small CSS file that will style the Notification bar. This is done purposely so that it is super easy to customize in the CSS so the look and feel is completely up to you or you designer.

<link href="path-to/notify.css" type="text/css" rel="stylesheet" />
<script src="path-to/jQuery.js"></script>
<script src="path-to/notify.js"></script>

Now since you have the files plugged in you can literally use Notify from your console. If your using a Webkit browser hit ’option, command, I’ or on Firefox hit ‘F12‘. Now in your console tab type.

$.notify.success('Woot woot, plugin is working');

If it worked congrats if not check to make sure all three file are included in your webpage. So to close the notification type in the console.

$.notify.close();

This will close that notification. It was built this way so that you can use different functions to close and open the notifications. Like if  you want to show a loading notification while doing a large ajax call. You can open it before the call, then close it on success. You can even show a success or error notification after the call as well. Notify does not always need to be closed manually check below at the Options section for more closing options.

Modes

$.notify.mode('This is not a real mode');

I decided there should be different modes for Notify so that you can handle multiple styles without having to write much more code. There are four different modes. Success, Error, Alert, and Basic, these all have distinct coloring. to call the differnt mode is super easy.

$.notify.success('Success');

$.notify.error('Error');

$.notify.alert('Alert');

$.notify.basic('Basic');

You can probably see why it would be nice to have these distinct different looks, and I think the coolest part of this is if you dont like the colors all you have to do is change the CSS for the specific mode. The classes are very easy to spot eg. .notify-basic .

Options

$.notify.basic('String to be read', {options});

Of course what is a plugin without options. So when this is published there is a total of three option. Two are specifically for closing and the other is a space based option.

Closing with Style

Auto Close

So there are some notifications that only need to be seen for a period of time. For example if you use this to notifie your uses that their mail was sent from an online form successfully. Use auto close to close the notification after a small period of time. To use auto close its simple.

$.notify.success('This will close in time', {autoClose: 3000});

As you can see the the parameter takes a number. This goes by milliseconds and the example above displays for 3 seconds.

User Close

Lets say you really want the user to see this notification but you would like them to be able to close the notification if they would like. Well this option will do that very thing. All it adds is a small X by the right corner. Once clicked it will close the notification.

$.notify.error('You need to close me!', {close: true});

This takes a boolean ‘true’ or ‘false’. There is no need for false because it will set to false automatically. So it only needs to be declared when it need to be true.

Occupy Space

This will allow the notification to make space for itself based on the height of the notification. Lets assume you want to call notify at the beginning of the page load. You should not also cover up the top content which you will if you dont set this option to true.

$.notify.alert('Im going to move everything down' {occupySpace: true});

This just like ‘close’ will only work with a boolean true.

Further Reading

To Download go to the homepage

Notify is open source

Notify’s animations use CSS3 transitions. If your browser supports them it will use them. If it does not, it will fallback to a javascript animation.

Also Notify works pretty well on new mobile Webkit browsers, but does not act very good on IOS4 and lower. Other mobile browsers not tested. If you have some insight let me know in the comments.

Close X