/    Sign up×
Community /Pin to ProfileBookmark

Adding pause and play buttons to a slideshow

Hello everyone,

I spent a while figuring out how to get a Js slideshow to work on a website and then my client asked me to add a pause, play, back and forward button to it. I haven’t had any luck trying to add one so I was wondering if anyone could lend me a hand.

Here is the code for the slideshow:

[CODE]
<script type=”text/javascript”>

$(document).ready(function(){
$(“.samples img”).fadeTo(“normal”, 1.0); // This sets the opacity of the samples to fade down to 60% when the page loads

$(“.samples img”).hover(function(){
$(this).fadeTo(“normal”, 0.6); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo(“normal”, 1.0); // This should set the opacity back to 60% on mouseout
});
});

</script>
[/CODE]

[CODE]
start_slideshow(1, 10, 13000);

function start_slideshow(start_frame, end_frame, delay) {
setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}

function switch_slides(frame, start_frame, end_frame, delay) {
return (function() {
Effect.Fade(‘slideshow’ + frame);
if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
setTimeout(“Effect.Appear(‘slideshow” + frame + “‘);”, 850);
setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
})
}
[/CODE]

Thanks.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJul 09.2010 — [B]In general[/B] I would do something like:

1) In your start_slideshow() include an argument called dir which will have a value of -1 or +1. Then increment frame by the value of dir.

2) In your "Play" button, call start_slideshow() and pass a value of +1 for dir.

3) In your "Back" button, call start_slideshow() and pass a value of -1 for dir.

4) The pause button just simply clears the setTimeout() and stores the current frame number in a global variable.
Copy linkTweet thisAlerts:
@erikw46authorJul 09.2010 — tirna,

Thanks for the reply. I have to admit that I am not very knowledgeable when it comes to JS. I modified this script from a source that I found online so I can't say that I would really know how to go about implementing the advice you gave me.
×

Success!

Help @erikw46 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...