admin » 19 July 2009 » In Ajax Articles »
The Yahoo UI library is the reason for most of the cool functions you see on some of Yahoo’s sites, like Flickr and Delicious. It’s still in active development by Yahoo and the community of YUI developers. It offers a lot of functions, Ajax support and animation effects. It’s cross-browser, and it’s packed with rich UI elements, like dialogs, calendars, WYSIWIG editors, sliders and DataTables. Both demos and documentation can be found at developer.yahoo.com/yui
The YUI Animation library
In our example, we’ve put together a few examples on how to use the Yahoo animation library. The first thing we did, was to include the YUI core and the minified version of the YUI animation library. We include these two files directly from Yahoo’s own servers, both to save bandwith, and to let the visitors use the cached version of the files if they’ve already visited a site that’s using these. The code for including the scripts:
<!-- YUI Core -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<!-- YUI Animation Library -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/animation/animation-min.js"></script> |
Now we have the javascripts we need. Next thing to do is to use them. This block shows you the code for the first example:
<div class="block">
<h3>Animating a property</h3>
<p>Click the block below to animate the width of the block.</p>
<div id="demo1"></div>
<script type="text/javascript">
YAHOO.util.Event.on('demo1', 'click', function() {
var anim = new YAHOO.util.Anim(this, { width: { to: 200} });
anim.animate();
});
</script>
</div> |
Check all the examples on our demo site: YUI examples
If you want to download the whole example, you can do so here:
Continue reading...
Tags: ajax, Javascript, tutorial, xhtml, yahoo, yui
admin » 31 July 2008 » In Ajax Articles »
In many cases, you want to show pictures on your website. In some of these cases, you’ll want users to upload their own pictures. This could mean that you would have to build an upload system, with lot’s of security issues around it, and it also means that you’ll have to have a lot of webspace available at your webhost. Luckily, there is a really easy and neat solution to this.
Flickr has been the number 1 for storing pictures online for some years, and they are offering developers a nice API, which means that we can use many of their functions in our own solutions. In this case, we are going to use it to grab the latest pictures from a Flickr group. But how? With JSON (JavaScript Object Notation). Jquery is able to transfer data between domains, and this means that with a little code, we can use this to show our pictures from the rss feed from the Flickr group.
I’ve put together an example on how to do this (you can download this as a .zip file at the bottom of the article).
What you need to pull this together is:
- Jquery
- A couple of lines in your htm file
- Another couple of lines in your css document
- A Flickr rss (doesn’t have to be yours, just a Flickr rss)
This is the code you need to put in your htm file (in the head tag):
<link rel="stylesheet" type="text/css" title="My style" media="screen" href="jsonstylesheet.css" />
<script src="js/jquery-1.2.6.pack.js" type="text/javascript"></script> |
And put this where you want inside the body tag (change the url to your own Flickr Rss feed):
<script type="text/javascript">
$.getJSON("http://api.flickr.com/services/feeds/groups_pool.gne?id=807213@N20&lang=en-us&format=json&jsoncallback=?", function(data){
$.each(data.items, function(i,item){
$("<img/>").attr("src", item.media.m).appendTo("#images")
.wrap("<a href='http://www.csstemplatesweb.com/ajax-articles/json-flickr-feed-example/'></a>");
});
$("#title").html(data.title);
$("#description").html(data.description);
$("#link").html("<a href='http://www.csstemplatesweb.com/ajax-articles/json-flickr-feed-example/' target=\"_blank\">Click here to get to the Flickr group</a>");
//Notice that the object here is "data" because that information sits outside of "items" in the JSON feed
});
</script> |
You also need to put this into your body tag (where you want the images to show):
<p>Only the last 20 pictures added to the Flickr group will show. To check out all the pictures, go to the Flickr group here:</p>
<p id="link"></p>
<div id="images"></div> |
To add some styling, add this in you css file:
#images { width: 500px; padding:0; margin:15px 0px 0px 100px; overflow: hidden; }
#images img { border:none; padding-right:5px; padding-bottom:5px;} |
That’s it!
Here is a little screenshot on how it will look. Of course, you can style it the way you want with css.

You can download the zip file, containing all you need.
You can also buy the “Personal homepage” css template, containing this function (only a bit more fancy), plus it integrates feeds from both Twitter and Delicious as well.
Continue reading...
Tags: ajax, Feed, Flickr, Javascript, jquery, Json