Jquery's a powerful javascript Framework and nowadays's a commonly use by web-developers all around de globe.
This will be my first snippet using Jquery, as you can easily see by going throughout the javascript-related snippets in this website, I didn't use, this is just because I always to try to implement this simple snippets without using a framework.
Jquery and other frameworks are very powerful and allow us to simplify many tasks, such as: event handlers; animations, DOM interaction; etc; etc; leaving us more time to enhance our application or giving us time to other projects.
If I'm allowed to give you an advice, first try to understand javascript concepts and all its power, try to get familiar with the language, and then choose a framework and start using it, you'll understand it better, and learning curve will be shorter.
Professionally I use Jquery but since this website's only a hobby, that's why I always wrote javascript snippets without any framework help, from now on I'll try to do both.
For a first jQuery snippet, a simple image Gallery.
This is like version 0.1, in the future I'll add more options, you can see it as a Jquery Image Gallery series.
But for the first version, this gallery will basically animate our images and will cycle them, i.e, it'll loop indefinitely; it'll have a preloader and each image transition will have an animation, it will adopt to the image dimensions. You can easily configure it to your needs.
This gallery will have lazy loading, this is, it'll only load the images when strictly needed, so you can have as many images as you want to, without impacting your page initial loading.
CycleGalleryInit.js, in this file we'll create our images array and start our gallery animation. The most important thing is that you understand how you can add your own images.
Our images array will have as many objects, as files you want to add to the gallery, each object image will have two properties:
img: our filename or the complete path including the filename, this is, let's suppose you have all the images in the same folder, you can only write the filenames without the path to them, but, you have to specify the path in another property, you'll see ahead; but if for instance you have images in different locations, than you have to write the full location.
title: this is the picture title, in this version will only fill images "alt" and "title" attributes;
Our array will have the following structure:
var images = [
{img: "image_filename.extension", title: "This is a title"},
{img: "image_filename2.extension", title: "This is another title"}
];
The other property in our gallery's path, as I wrote previously if you have all the images in the same folder, you can omit it in image location, but you'll have to give that information in this property (but, well, if you have all your html, javascript and images file in the same folder, you don't have to give a path ^_^'') CycleGalleryInit.js
$(document).ready(function(){
//images object
var images = [
{ img: "1.png", title: "Picture 1"},
{ img: "2.jpg", title: "Picture 2"},
{ img: "3.jpg", title: "Picture 3"},
{ img: "4.jpg", title: "Picture 4"},
{ img: "5.jpg", title: "Picture 5"}
];
//start our animation
$("#wide_gallery").aCycleGallery({
imgs: images,
path: "images/"
});
});
Our html file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"