Saturday, January 1, 2011

A Simple jQuery Slideshow

For starters, our main goal should be keeping the markup as clean as possible:

Now let’s use CSS to position the images on top of each other and bring the active image to the top level with z-index:

#slideshow {

position:relative;

height:350px;

}

#slideshow IMG {

position:absolute;

top:0;

left:0;

z-index:8;

}

#slideshow IMG.active {

z-index:10;

}

#slideshow IMG.last-active {

z-index:9;

}

Due to absolute positioning, we need to define the height of the slideshow DIV. Also, notice that we defined three different z-indexes—we will manipulate these soon using jQuery.

For the slideshow animation we are going to switch between each photo at a set rate. So let’s start by writing a function that brings in a new photo on top of the last active image:

function slideSwitch() {

var $active = $('#slideshow IMG.active');

var $next = $active.next();

$next.addClass('active');

$active.removeClass('active');

}

$(function() {

setInterval( "slideSwitch()", 5000 );

});

Here we set a JavaScript interval to call slideSwitch() every 5 seconds. Then slideSwitch() applies the CSS class ‘active’ to bring the next image to the top of the stack. Since we will select the images more than once within slideSwitch(), we define the variables $active and $next for selector performance.

Next we should incorporate a fade animation. For a gallery like this, fade in and fade out are identical, but let’s not forget to think about what we fade against:

function slideSwitch() {

var $active = $('#slideshow IMG.active');

var $next = $active.next();

$active.addClass('last-active');

$next.css({opacity: 0.0})

.addClass('active')

.animate({opacity: 1.0}, 1000, function() {

$active.removeClass('active last-active');

});

}

$(function() {

setInterval( "slideSwitch()", 5000 );

});

We start by applying the ‘last-active’ class we defined earlier. Since ‘.last-active’ falls after ‘.active’ in the stylesheet, the z-index of 9 takes priority, and the top image drops back a level. Next, we set the opacity of the new image to 0 so that we can fade it in using the animate() function. Finally, we attach a callback to remove the z-index classes from the previous image when animate() completes.

Although our slideshow is working well, we should make it more robust by building in some default variables. First, let’s define a default active image, in case we need to put less stress on the back-end. Also, we can use defaults to make the gallery animation loop.

function slideSwitch() {

var $active = $('#slideshow IMG.active');

if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

var $next = $active.next().length ? $active.next()

: $('#slideshow IMG:first');

$active.addClass('last-active');

$next.css({opacity: 0.0})

.addClass('active')

.animate({opacity: 1.0}, 1000, function() {

$active.removeClass('active last-active');

});

}

$(function() {

setInterval( "slideSwitch()", 5000 );

});

We first define a default image for the $active variable, which interestingly enough needs to be the last image on the stack. This is because through absolute positioning, the last image appears on top, and we need to start with it if we want to avoid any flicker.

For the loop it is pretty simple: all we have to do is point the $next variable to the first image once it has gotten to the end of the line.

If you want to improve this function, try setting the animation speed with a variable so the main slideshow function can be thrown into the core and left alone. Also, this slideshow is easily converted to support DIV’s instead of IMG’s—try programming a slideshow with more content.


Prachar is the owner of IndSEO, A India based search engine marketing firm offering a variety of SEO related services including Reputation Management, Social Media Marketing, Email Marketing, Website Conversion Metrics and Mobile Phone Application Development. Please contact Prachar@ymail.com to learn more.


Share

|

How to Add Slideshow in Blogger?

Adding Slideshow to your blog can be a fun way to draw visitors or to promote your art or photography for a business blog. Here's how to add one to your site. Note that as of today, Jan. 01, 2011, there are still bugs in the Slideshow program; but read on for some suggestions for overcoming those bugs. They're easy and work like a charm.

Instructions

Log on to your Photobucket album.

Create a "subalbum" (if you haven't already) by uploading photos that you'd like for your Slideshow. Note-- do not choose the "create a Slideshow" option in Photobucket.

Keep your Photobucket page open for later use.

Log on to Blogger in another window.

Go to "Dashboard."

Click "Layout."

Click "Add gadget."

Click "Slideshow."

Title your Slideshow and then choose "other." Keep this window open.

Go back to Photobucket and at the bottom of your "subalbum" in the left hand corner it will say "public feed" and "album feed."

You want to right click on "album feed" to open it in a new window. If you click on "public feed" it will create a Slideshow of all of your Photobucket images.

Copy that URL.

Go back to blogger and paste that "subalbum" feed address into the box that says "feed."

Preview the Slideshow.

Save changes. You're done.

Create a Free Slideshowtripwow.tripadvisor.com/slideshow

Create free stunning videos from your travel photos in minutes

Auto Publish Your Blogdlvr.it

Distribute Your Blog to Twitter Fast. Easy. Free. Schedule Posts.

Plugin For Blogs - Gamesdailygame.org

Automatically post a new flash game to your blog every day

Get Twitter Followerstwiends.com

Get twitter followers on this novel new service. No auto-tweeting.


Prachar is the owner of IndSEO, A India based search engine marketing firm offering a variety of SEO related services including Reputation Management, Social Media Marketing, Email Marketing, Website Conversion Metrics and Mobile Phone Application Development. Please contact Prachar@ymail.com to learn more.

BACK LINKS - Weak links or strong links?

This is a question that raises a lot of debate among the SEO and internet marketing communities. Some argue that it is far better to work on building lots of links that perhaps have lower power, whilst others feel that gaining a few very powerful links is the way to go.

As I have quite a lot of experience in of link building I thought I would give the pros and cons of both type of link and explain which I think is best.

Weak Links

It is not actually that easy to define what makes a link strong or weak, but for the sake of this article we will consider a weak link to be any link from a site with a PageRank of under 3 and have less than 1000 links pointing to its domain.

I realise this is a bit of a crude generalization, but it gives an rough impression of the kind of links I am talking about.

Pros:

  • These links are often easier to build than powerful links, meaning more can be gained in the same space of time.
  • With less powerful links it is often easier to link to deeper pages on your site, thus helping power distribution and the ranking of pages lower in the site hierarchy.
  • It is often easier to acquire your anchor text of choice when building weak links, and this is important when trying to rank for your desired keywords.
  • As weak links are quicker and easier to build, you can gain links from many more independent domains compared to when building powerful links. Domain spread of links is very important.

Cons:

  • Weak links don’t pass a great deal of link juice to your site.
  • Weak links can often look spammy, despite whether they are have been acquired by white-hat or black-hat techniques.
  • Weak links are more likely to drop off over time as the sites linking to you have a greater chance of shutting down or being redeveloped.
  • Weak links are easier for your competitors to match or acquire for themselves.

Powerful Links

For the sake of this article will class powerful links as having the opposite traits as weak links. That is to say any link with a PageRank of 3 or more, and over 1000 back links.

Pros:

  • These links pass more link juice to your site. This power is then more likely to spread to deeper pages and help you rank for a wider spectrum of keywords due to increased authority in the eyes of search engines.
  • More powerful links tend to provide more traffic than weak links as the sites linking to you are by definition often more authoritative and more popular.
  • Powerful links not only help increase your site-wide ranking ability, but they also improve you perceived trust, making you less likely to be penalized for any Grey-hat activity.
  • Powerful links are less likely to be removed than weak links and are harder for your competition to acquire.

Cons:

  • Powerful links tend to take more time to procure meaning you get less of them for your efforts.
  • More powerful websites are less likely to provide a link to deeper pages in your site and some do not provide anchor text links.
  • Because powerful links pass more link juice and have a larger effect on site power, when they are removed for whatever reason, the negative ramifications tend to be larger for your site.

So there you have it, a summary of the strengths and weakness of strong and weak links. So what you may ask is my concluding advice? Well, perhaps rather predictable I suggest garnering a mixture of the two.

It is very difficult to build links to every page of your site so powerful links are useful for enhancing the profile a little for all your pages.

However, when you are trying to rank very specific pages for certain keywords, lots of weaker links can often do the trick due to multiple instances of targeted anchor text links.

Prachar is the owner of IndSEO, A India based search engine marketing firm offering a variety of SEO related services including Reputation Management, Social Media Marketing, Email Marketing, Website Conversion Metrics and Mobile Phone Application Development. Please contact Prachar@ymail.com to learn more.