Skip to content
Browse files

Implemented basic support for a slide event

  • Loading branch information...
1 parent 9e38ab8 commit dbb96733e977c9ca1d411ab47d2fdbe2bf69ad3e @oyvindkinsey committed
Showing with 24 additions and 6 deletions.
  1. +11 −1 JsSlideshow.js
  2. +13 −5 index.html
View
12 JsSlideshow.js
@@ -21,9 +21,13 @@ function JsSlideshow(config){
}
else {
// slide
+ var prevIndex = index;
if (++index == config.images.length) {
index = 0;
}
+ if (config.listeners.slide) {
+ config.listeners.slide(config.images[prevIndex], config.images[index]);
+ }
var prevImage = image;
image = config.images[index].dom;
// move the image to the back
@@ -50,6 +54,9 @@ function JsSlideshow(config){
};
target.style.cursor = "pointer";
}
+ if (!config.listeners) {
+ config.listeners = {};
+ }
// load the images
for (var i = 0, len = config.images.length; i < len; i++) {
image = document.createElement("img");
@@ -57,12 +64,15 @@ function JsSlideshow(config){
image.style.top = "0px";
image.style.left = "0px";
image.src = config.images[i].url;
- image.title = config.images[i].name;
+ image.title = config.images[i].title;
target.insertBefore(image, target.firstChild);
config.images[i].dom = image;
}
image = config.images[0].dom;
//start a slide
+ if (config.listeners.slide) {
+ config.listeners.slide(null, config.images[index]);
+ }
timer = window.setTimeout(function(){
_fade(1);
}, time);
View
18 index.html
@@ -16,6 +16,8 @@
<body>
<div id="slideshow">
</div>
+ <div id="name">
+ </div>
The code needed:
<br/>
<pre>
@@ -31,24 +33,30 @@
and is shared a under Creative Commons Attribution.
<script type="text/javascript">
(function(){
+ var name = document.getElementById("name");
var sl = new JsSlideshow({
target: "slideshow",
images: [{
url: "images/4504470765_90aa261be6.jpg",
- text: "foo"
+ title: "foo1"
}, {
url: "images/4510204607_42bbb55d9c.jpg",
- text: "foo"
+ title: "foo2"
}, {
url: "images/4510826808_f6edfc906a.jpg",
- text: "foo"
+ title: "foo3"
}, {
url: "images/4513712885_0c008e3638.jpg",
- text: "foo"
+ title: "foo4"
}],
transition: 3000,
time: 2000,
- url: "http://www.flickr.com/photos/bobowen"
+ url: "http://www.flickr.com/photos/bobowen",
+ listeners: {
+ slide: function(from, to){
+ name.innerHTML = to.title;
+ }
+ }
});
})();
</script>

0 comments on commit dbb9673

Please sign in to comment.
Something went wrong with that request. Please try again.