PDA

View Full Version : Add Slide Numbers to Background Carousel?



scquarterhorses
03-06-2012, 01:25 AM
1) Script Title: Background Carousel Slideshow

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex14/bgcarousel.htm

3) Describe problem: I was wondering if there was a way to add the slide numbers for this slideshow, for example, "Slide 1 of 3." How would one go about doing this?

vwphillips
03-06-2012, 10:16 AM
slide:function(nextslide, dir){ //possible values for dir: "left", "right", "top", or "down"
if (this.curslide==nextslide)
return
var slider=this, setting=this.setting
var createobj=bgCarousel.routines.createobj
var nextslide_initialpos=setting.dimensions[(dir=="right"||dir=="left")? 0 : 1] * ((dir=="right"||dir=="down")? -1 : 1)
var curslide_finalpos=-nextslide_initialpos
var posprop=this.posprop
this.XofY(nextslide);
if (this.animation_isrunning!=null)
this.animation_isrunning=true //indicate animation is running
this.$imageslides.eq(nextslide).show().css(createobj([posprop, nextslide_initialpos], ['opacity', 0.5])) //show upcoming slide
.stop().animate(createobj([posprop, 0]), setting.slideduration, function(){
var $this=jQuery(this)
$this.addClass(setting.activeslideclass).animate({opacity:1})
.find('div.desc').stop().slideDown()
slider.animation_isrunning=false
})
.find('div.desc').hide()

this.$imageslides.eq(this.curslide)
.removeClass(setting.activeslideclass)
.stop().animate(createobj([posprop, curslide_finalpos]), setting.slideduration, function(){
var $this=jQuery(this)
$this.hide()
}) //hide outgoing slide

this.curslide=nextslide
},





init:function($, slidesHTML){
var slideshow=this, setting=this.setting
this.$wrapperdiv=$('#'+setting.wrapperid)
setting.dimensions=[this.$wrapperdiv.width(), this.$wrapperdiv.height()]
this.$wrapperdiv.css({position:'relative', visibility:'visible', overflow:'hidden', backgroundImage:'none', width:setting.dimensions[0], height:setting.dimensions[1]}) //main DIV
if (this.$wrapperdiv.length==0){ //if no wrapper DIV found
alert("Error: DIV with ID \""+setting.wrapperid+"\" not found on page.")
return
}
this.$wrapperdiv.html(slidesHTML)
this.$imageslides=this.$wrapperdiv.find('div.slide').hide()
this.$imageslides.eq(this.curslide).show()
.css(bgCarousel.routines.createobj(['opacity', 0.5], [this.posprop, 0])) //set current slide's CSS position (either "left" or "top") to 0
.addClass(setting.activeslideclass)
.stop().animate({opacity:1})
.find('div.desc').slideDown()
var orientation=setting.orientation
var controlpaths=(orientation=="h")? setting.navbuttons.slice(0, 2) : setting.navbuttons.slice(2)
var $controls = $('<img class="navbutton" src="'+controlpaths[1]+'" data-dir="forth" style="position:absolute; z-index:5; cursor:pointer; ' + (orientation=='v'? 'bottom:0; left:46%' : 'top:46%; right:0;') + '" />'
+ '<img class="navbutton" src="'+controlpaths[0]+'" data-dir="back" style="position:absolute; z-index:5; cursor:pointer; ' + (orientation=='v'? 'top:0; left:45%' : 'top:45%; left:0;') + '" />'
)
.click(function(){
var keyword = this.getAttribute('data-dir')
setting.curslide = (keyword == "right")? (setting.curslide == setting.content.length-1? 0 : setting.curslide + 1)
: (setting.curslide == 0? setting.content.length-1 : setting.curslide - 1)
slideshow.navigate(keyword)
})
$controls.appendTo(this.$wrapperdiv)
if (setting.displaymode.type=="auto"){ //auto slide mode?
setting.displaymode.pause+=setting.slideduration
this.maxsteps=setting.displaymode.cycles * this.$imageslides.length
if (setting.displaymode.pauseonmouseover){
this.$wrapperdiv.mouseenter(function(){slideshow.ismouseover=true})
this.$wrapperdiv.mouseleave(function(){slideshow.ismouseover=false})
}
this.rotatetimer=setTimeout(function(){slideshow.rotate()}, setting.displaymode.pause)
}
this.xofy=document.getElementById(setting.SlideNuID);
this.XofY(this.curslide);
},


XofY:function(nu){
if (this.xofy){
this.xofy[this.xofy.nodeName.toUpperCase()=='INPUT'?'value':'innerHTML']=(nu+1)+' of '+this.$imageslides.length;
}
}




var firstbgcarousel=new bgCarousel({
wrapperid: 'mybgcarousel', //ID of blank DIV on page to house carousel
imagearray: [
['http://www.vicsjavascripts.org.uk/StdImages/Egypt5.jpg', '<h2>0Autumn Day</h2>The sun peaks through the trees, a knife that cuts through the chill, crisp air.'], //["image_path", "optional description"]
['http://www.vicsjavascripts.org.uk/StdImages/Egypt6.jpg', '<h2>1Wind Chime</h2>The bellweather of the sky, the chime speaks of impending turmoil.'],
['http://www.vicsjavascripts.org.uk/StdImages/Egypt7.jpg', '2The scent of spring invigorates her as she inhales whilst the warm breeze brings a wave of tranquility.'],
['http://www.vicsjavascripts.org.uk/StdImages/Egypt8.jpg', '3Alone and Lonliness- Peace and Inner Struggle'] //<--no trailing comma after very last image element!
],
displaymode: {type:'auto', pause:3000, cycles:2, stoponclick:false, pauseonmouseover:true},
navbuttons: ['left.gif', 'right.gif', 'up.gif', 'down.gif'], // path to nav images
activeslideclass: 'selectedslide', // CSS class that gets added to currently shown DIV slide
orientation: 'h', //Valid values: "h" or "v"
persist: false, //remember last viewed slide and recall within same session?
slideduration: 500, //transition duration (milliseconds)
SlideNuID:'tst'
})




<div id="mybgcarousel" class="bgcarousel"></div>
<input id="tst" />