I couldn’t help myself writing about this plugin. It’s one of the most creative things i’ve seen made with jQuery. As the name tells you, before-after, you can smell some actions, right? Take a look at the picture here :

before-after

The plugin allows you to show two pictures of the same thing in different times showing some differences. Of course we can understand the differences when two images are shown side by side BUT superimposing on the other and having a slider to slide them and see the difference is simply awesome and that’s what we call creativity. A series of demo is here http://www.catchmyfame.com/jquery/demo/8/ . Moreover the slider is smooth and when you click on any part of the image, the slider comes to the cursor smoothly – quite impressive.

The guy at http://www.catchmyfame.com did a really nice job. We’d expect a vertical slider if possible from this plugin’s next release.  Have fun with it.

I’ve always been a big fan of jQuery Grid Plugin jQGrid. It can handle quite complex and sophisticated tasks. But i didn’t like the ui it was before. I had to modify their css to be able to present them to clients. I also use flexigrid for simpler tasks. It’s quite easy to work with. But none of them were nowhere closer to defeat Jack Slocum’s EXT JS Grid. Ext was heavy for me as i was learning them and eventually found that my applications don’t require the desktop feelings as extjs provided. And being a big fan of jQuery , i always wanted to have a grid plugin that works close to ExtJS grid. Now look at this.

jqgrid

Awsome, right ? Yes,  jqGrid at trirand is now powered by jQuery UI. It’s quite neat and fast now. You can customize the theme from jQuery UI site as well. No more talks now,  just eat it here http://www.trirand.com/jqgrid35/jqgrid.html

So it’s not flash after all to do all the magics! We have seen and still seeing flash doing wonders and magics. One of the cool things that was developed was pageflip. I saw that first when i was playing with flash in 2002-2003 i guess in flashkit and actionscripts.org. You can see a very good pro version of such thing here. But for us, who want most of the things done in jQuery – finally has an alternative to that page flip thing.  It’s not a fully alternative of flash but not bad for minimal use page flip effect.

page_flip

That’s how it looks with a plugin called jFlip written by Renato Formato at http://www.jquery.info/scripts/jFlip/demo.html

The demos on that pages has different setups with some options. And i created one with some of my dream cars here

Hope you like the initiative  by Renato. 

05 May, 2009

Easily create an animated nav menu

Posted by: Mahbub In: misc

This is a very short post of how we can easily create an animated navigation menu with jQuery without any plugin. You must have seen horizontal or veritical navigation menus that expands and contracts its size on rollover. Before these javascript framework came, we had to do quite a lot of code to get the things done. Why? That stupid cross browser handling. I don’t want to start over on IE. 

Ok, here’s the thing. We’re simply using an unordered list to make a horizontal menu that expands and contracts. Code is dead simple. Let’s look at the markup first.

<div id="navcontainer">
<ul id="navlist">
	<li><a href="http://www.google.com">Google</a></li>
	<li><a href="http://www.yahoo.com">Yahoo</a></li>
	<li><a href="http://www.msn.com">MSN</a></li>
	<li><a href="http://www.lycos.com">Lycos</a></li>
	<li><a href="http://www.baidu.com">Baidu</a></li>
</ul>
</div>

So we have some list items there. So make them appear like horizontal menu we’d need some css which looks like this

*{
font-family: arial, helvetica, sans-serif;
}
#navcontainer ul
{
padding-left: 0;
margin-left: 0;
background-color: #222;
color: White;
float: left;
width: 100%;
font-size:13px;
text-transform:uppercase;
font-weight:bold;
}
 
#navcontainer ul li { display: inline; }
 
#navcontainer ul li a
{
padding: 0.7em 1.8em;
background-color: #222;
color: White;
text-decoration: none;
float: left;
width:100px;
border-right: 1px solid #fff;
}

And the final part .. Making them dance on mouseover. Quite simple with the animate function. Just couple of these lines below will do the trick. Have a look.

	$(function(){
		$("#navlist a").hover(function(){
			$(this).css("background-color","#369");
			$(this).animate({ width: '200px'}, {duration: 200,queue:false});
		},
		function(){
			$(this).css("background-color","#222");
			$(this).animate({ width: '100px' }, {duration: 200,queue:false});
		});		
	});

That’s it!! See it in action

Are you bored with too many lightboxes, thickboxes, window overlays ? Do you want an inline gallery kinda thing? May be you do. I’ve heard from some of clients (older clients) that they don’t like this blackouts when lightboxes, thickboxes. So what to do then ? One thing, when u think of something, try good first, in 80% of the cases you’ll find a solution that some one has already made. It’s not a Newton’s century, it’s 21st century. So many people are after so many things. And a German guy named Christoph Schüßler comes to rescue us from ordinary lightboxes. It’s called jQuery popeye.

popeye

I don’t want to make the story longer. Just see it in action. And I’m sure you’ll plan to use this plugin in some of your next projects.

14 Apr, 2009

Easy AJAX link – no plugins needed!

Posted by: Mahbub In: ajax

So AJAX AJAX and AJAX, that’s what we do extensively these days. It saves time, adds dynamics and gives you a feel of using an software application kind of feel. There’re many ways to use AJAX with many libraries. But as you can see this site is for jQuery, we’ll look at the basic or perhaps some advanced AJAX usages.

What do you we need ?

jQuery library (of course)
A tiny php script

Let’s began talking. In jQuery, there are basically 6 types of method to do AJAX operations. These are

  1. $.ajax(options)
  2. $.get(url, data, callback)
  3. $.getJSON(url, data, callback)
  4. $.getScript(url, callback)
  5. load(url, data, callback)
  6. $.post(url, data, callback,

Apart from number 1, all the other methods use $.ajax internally. So that means $.ajax() is our mother function for jQuery AJAX operations.  Let’s look at how $.ajax() looks like

$.ajax({
    type: "POST",
    url: "some.php",
    data: "name=Peter&amp;location=NY",
    success: function(msg) {
        alert("Server Response " + msg);
    }
});

That’s pretty it. The type parameter takes “GET” or “POST” which means you can send AJAX requestion as POST or GET (I’d prefer POST always). The rest of the parameters are pretty self explanatory if you take a look at the code again.

Now we’re going to make a small AJAX script that reads the link of hyperlink tags (<a>) and loads the request on some div elements in the document.

First we take a normal html of php document which will look like this

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
	<title>Ajax link test</title>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<script type="text/javascript" src="jquery-1.2.6.min.js"></script>	
</head>
<body>
</body></html>


Now let’s add some links to the document. For a better menu kind of look we’ll use a UL>LI and Link . That will look like this

<ul id="nav">
	<li><a class="ajax_link" rel="div1" href="response.php?user=john">Load in Div 1</a></li>
	<li><a class="ajax_link" rel="div2" href="response.php?user=nash">Load in Div 2</a></li>
	<li><a class="ajax_link" rel="div3" href="response.php?user=stella">Load in Div 3</a></li>
	<li><a class="ajax_link" rel="div4" href="response.php?user=jason">Load in Div 4</a></li>
</ul>

As you can see we have put links in list elements inside an unordered list object. Take a closer look at the <a> tag’s properties. We have href , class and rel attribute which looks nothing different than a normal link. If you see, we have given the rel attribute to some div names namely div1, div2 .. so on. This means we want the response of the href to be loaded into those divs. How to do that ? Let’s add those divs first

<span>DIV -1 </span>
<div id="div1" class="content_loader"></div>
<span>DIV -2 </span>
<div id="div2" class="content_loader"></div>
<span>DIV -3 </span>
<div id="div3" class="content_loader"></div>
<span>DIV -4 </span>
<div id="div4" class="content_loader"></div>

And the real part now – we have given the links a class “ajax_link”. We’ll only dynamically add ajax actions only links having a class name called “ajax_link”. Hell, we don’t all the links of a page to have ajax actions, do we?

So, on document load we’d do this.

    $(document).ready(function() {
        $("a.ajax_link").click(function() {
            $current_link = $(this);
            $.ajax({
                type: "post",
                url: $current_link.attr("href"),
                success: function(e) {
                    $("#" + $current_link.attr("rel")).html(e);
                }
            });
            return false;
        });
    });

Let me explain the script a bit. The document.ready event is a event which is triggered at page load. And then we’re assigning some sort of codes on the click event of the links who have a class “ajax_link”. Doing this $current_link=$(this); allows to have the current link object be available within the callback function.  And we have

$(“#”+$current_link.attr(“rel”)).html(e)

which means $(“div_id”).html(server_response) and we have set the url param of the $.ajax function dynamically with       url :$current_link.attr(“href”).  So now all those means “All those links who have a class “ajax_link” – Add a click event handler — then execute and AJAX request taking the links href poperty and load the response into a div whose id matches the “rel” attribute of the link”. And the return false prevents the link work like normal link ;)

Wanna see it an action ? Here it goes.

And you can download the source as well.

In the next section of this little tutorial we’ll be using the same thing but with a little bit of comfort.

Applying easier method

Everything remains almost the same. We’ll just change the ajax method here . So instead of writing the whole $.ajax block we can achieve the same thing with the following.

$(document).ready(function(){
$("a.ajax_link").click(function(){
$("#"+$(this).attr("rel")).load($(this).attr("href"));
return false;
});
});

It’s lot less complicated now, right? The load method loads the ajax content within the element it’s attached to. If $(“#somediv_id”).load(“mypage.php”), it’ll try to load mypage.php ’s  content in it. Pretty simple, huh? But i suggest you get used to the main method (shown in the first part).

In the zip file there’s another file called ajax2.php which demonstrates this methos which has the same result.

So, AJAX is not as hard as it sounds, right ? When you become very fluent with AJAX operations, you’ll create magics.

Thanks for reading btw.

With the advancement of DHTML, we can do lot of things with just blink of an eye.  We all have used window overlays or lightboxes at some point of time these days. But sometimes it becomes necessary to block part of the page or any specific element, e.g a DIV so that people are not able to play with your page when you don’t want them to. Like if someone is making a comment on a comment box, you don’t want people to click on other comments while filling it up. What to do then? Well there’s a neat jQuery solution. You simply block them while commenting. And there may be lot of cases like that when we want to block the whole page or certain elements. jQuery BlockUI comes to rescue.

blockui

It was initially made to block a whole page with message but now, it can block page element or even show Growl like message.  Check out the examples here. The documentation is very nice and fair amount of code examples are given. Use it in your application. If you have any problems using it, leave me a comment here.

Doing a portfolio page with Flash on your website has become kind of obsolete. These days with Faster machines and new generation browser can really kick some ass with Javascript and CSS.  JQuery has very neat way to deal with some effects. All the animations stem from the base method called “animate”. It animates, tweens the properties of DOM elements. To make the long story short take a look at this.

portfolio_demo

So, you have already clicked and saw right? Ok, if you look at the code, it’s fairly simple.

	$(document).ready(function(){
		var hover_in_easing="easeOutExpo";
		var hover_out_easing="easeOutBounce";
		$(".info_container").show();
		$("div.portfolio_div").hover(function(){
			$(this).find(".info_container").animate({top:"0px"},{duration: 400, easing: hover_in_easing});
		},function(){
			$(this).find(".info_container").animate({top:"100px"},{duration: 500, easing: hover_out_easing});
		});
                // The 100 px is the size of the mask
	});

It uses animate function to animate the mask over the image which is kept hidden by positioning relatively. And with easing plugin, we achieve some cool effect of bouncing when you hover out from the image.  You can put any html inside the info_container DIV elements as long as it doesn’t go beyond the borders. Look at the stylesheet and you’ll find it very gramatical. You can customize the sizes by modifying the div classes.

Download the Source

Inspiration : http://dibusoft.com/portfolio

Ever saw those transparent captions on images ? Captions poping out from the bottom or top describing the photo? I’m sure you have. There are lot of scripts like that.  And here comes our favorite jQuery version of that.

captify_demo

You can put plain, text, html or anything on there. Just take a look at their plugin home page and it’s pretty nicely described. No nasty tricks is needed. 

http://masterfidgeter.com/projects/captify/

Make your photo pages look good with it.

This week – March 20,09 jQueryMagic chooses jQuery colorbox as the pick of the week. You all have heard lot of lightbox, thickbox, greyboxes and different window overlays. It gets better in the newest plugin releases. This one really rocks. Fully customizable and easy to use. It’s lightweight and looks cool. Moreover a bunch of example is bundled with the library.

colorbox

colorbox

Go to the project page here.


Translator

Tags