How to use images for next and previous buttons with Views Slideshow (or, how to replace any textual link with an image)

This tutorial is sponsored by the Save Joseph campaign, a grassroots effort to find a good friend, stellar artist and all around amazing person a satisfying, creative job in the next 9 days. I know the Drupal community could use this kind of talent. Learn more about the effort at savejoseph.org.

Views Slideshow is a nice module that leverages the jQuery Cycle plugin to create a highly-customizable, attractive slideshow. It comes with an option to display simple text controls to go forward or back through the slides. What I wanted was to customize this experience with images instead of the Previous and Next links.

The first step is create a view using Views Slideshow and enable the controls on the top of the slideshow. This is done via the Views style settings dialog:

Once this is set, you should see some links above the slideshow:

To turn these links into images, we first need to find a unique identifier for each one. Views Slideshow adds a unique ID, so we can use that. Here's what I see in Firebug when I inspect the element:

You can see there is a unique ID for each element. Now, all we need to do is set a number of styles for the link.

First, we need to set the background of the element to use our image:

background:url('images/left-button-on.png');

Next, we need to set the dimensions of the element to match our image, which is 71 pixels by 71 pixels. If we didn't have to worry about the text, we would just set the width and height. But, we need to hide the text, so we're going to set the height o 0, and the top padding to 71, which will bump the text out of view:

width:71px;
height:0px;
padding-top:71px;

If you refresh your page at this point, you'll still see some text:

This is because we need to explicitly set any the element to hide any content that's outside of it's bounds. We do so by defining the overflow property to hidden:

overflow:hidden;

Finally, I didn't want a pause button, so I set to not display:

display:none;

The final result looks like this:

By the way, the artwork you see is produced by Joseph Cowman, if you haven't seen his stuff, it's brilliant.

And the code, with some particular styles for what I needed, is this:

#views_slideshow_singleframe_prev_gallery-block_1, #views_slideshow_singleframe_next_gallery-block_1 {
  width:71px;
  height:0px;
  padding-top:71px;
  position:absolute;
  top:100px;
  overflow:hidden;
}
#views_slideshow_singleframe_prev_gallery-block_1 {
  background:url('images/left-button-on.png');
  left:0px;
}
#views_slideshow_singleframe_next_gallery-block_1 {
  background:url('images/right-button-on.png');
  right:0px;
}
#views_slideshow_singleframe_playpause_gallery-block_1 {
  display:none;
}
Controls Top Determine if controls for the slideshow (start/stop/next/previous) should appear, and if so whether they should appear before or after the slideshow. and SO sli J:sh- Jk MR *-ii iv iujj- .uui iun~ t_ui in wis" Lup iitui iulk <div id-Views_slideshow_singleframe_controls_gallery- DLock_l class- Views_slideshow_singleframe_controls views_slideshow_controls" style-"display BLOCK block_l" views_slideshovi_previous" href-"# Previous block_l" views_slideshov»_pause" href-"# Pause <Za> block_l" views_slideshov»_next" href-"# V Next </c> </div> href href= DOS LUIZ AKA ID "views slideshow singleframe prev gallery- block CLASS " views Sl ideshow singlefrome previous VIEWS si ides how previous AKA id="views_ slideshow_ singleframe. playpause„ gallery- block III class "vietvs slideshow singleframe PAUSE VIEWS si ides how pause AKA id= VIEWS slideshow. singleframe. NEXT gallery- block III class " views slideshow singlefrome NEXT VIEWS ides how next" href BIG lp> s-11 vi avs_sl ingle romc_p rev us vi c*s_5 id us how_previ ou t.a bio ck.l11 las s-11 wi cws_sl ideshofl_si ngl ramc_pou sc clos vi ew_sl ideshow.si ngl romc_n cxt STYLE DISPLAY id=" vi ews_sli deshow_singl ef r ame_ controls„gal lery- class- "views si ideshow singLetrome controls vi ews_sl id eshow controls idU" view s_sl idesho*_si ngl ef rame_cont rol s_gal ry- bio ck_l s-11 viaws_sl ideshorrsi ngl ramecont rols uiews_l eshow_cont rol iglef slideshoiv idehoiv_ PL Ldc'iC.pr OF Icr clcchon TOO lr- I -i Jos dechon WING Icr LIES single dechon £tiq GAS sinjlcT 0,0 wic.prc jo jsnc. lock. viCi.s_s"L .dcfiho.Liii raric_playpflus jo vid.r.l.dcfiho" lock. JAR ni- BTR SQUAT IF .tnsilft ls,? WWI ilk:. 4i" t£t WILF FIG i >a 1 1 BOOB LO GRAMP IS«H|tll TO HR H'.-xl LT. Previous

Comments

Hi,

Thanks for the above, its exactly what i needed!
Just one question..
Where can i find the CSS &/or HTML location to edit..

Again many thanks

Post new comment

The content of this field is kept private and will not be shown publicly.