Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2012, 01:26 PM   PM User | #1
samslystone
New Coder

 
Join Date: Dec 2011
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
samslystone is an unknown quantity at this point
Jquery problem - adding previous and next to numbered slideshow

Hi all

Having a problem adding a 'next' and 'previous' button to the following page:

www.catherinehyland.co.uk/2012/work/work.html

Currently the user can navigate by clicking on the numbers. However, I would like to add a 'previous' link before the numbers, on the same line, and a 'next' link after the numbers, taking the user back and forward respectively. Can anyone help?

S
samslystone is offline   Reply With Quote
Old 12-15-2012, 01:47 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
I was about to say "what numbers" but I did Ctrl-A and I could (just about) see them: think they need to be a bit more prominent

I suggest you add and style the next and previous buttons firstly, before trying to add jQuery to them: it is difficult to discuss code for elements that don't yet exist!
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-15-2012, 02:57 PM   PM User | #3
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,354
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Code:
$(document).ready(function() {
 Next.lgth=8;
 Next.index=0;
 $("#nxt").click(function() {
  Next(1);
 });
 $("#bak").click(function() {
  Next(-1);
 });
 $("#cf7_controls").on('click', 'span', function() {
 $("#cf7 img").removeClass("opaque");
 Next.index = $(this).index();
 $("#cf7 img").eq(Next.index).addClass("opaque");
 $("#cf7_controls span").removeClass("selected");
 $("#cf7_controls span").eq(Next.index).addClass("selected");
});
});

function Next(ud){
 ud=Next.index+ud;
 ud=ud<0?Next.lgth:ud>Next.lgth?0:ud;
 $("#cf7 img").removeClass("opaque");
 $("#cf7 img").eq(ud).addClass("opaque");
 $("#cf7_controls span").removeClass("selected");
 $("#cf7_controls span").eq(ud).addClass("selected");
 Next.index=ud;
}
Code:
  <p id="cf7_controls">
<input id="bak" type="button" name="" value="Back" />
    <span class="selected">01</span>
    <span>02</span>
    <span>03</span>
    <span>04 </span>
    <span>05 </span>
    <span>06 </span>
    <span>07 </span>
    <span>08 </span>
    <span>09 </span>
<input id="nxt" type="button" name="" value="Next" />  </p>
    </p>
</div>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is online now   Reply With Quote
Users who have thanked vwphillips for this post:
samslystone (12-15-2012)
Old 12-15-2012, 05:04 PM   PM User | #4
samslystone
New Coder

 
Join Date: Dec 2011
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
samslystone is an unknown quantity at this point
Vic, thank you so much, you are a lifesaver!

Just one thing. Can I change the buttons so they appear simply as text, rather than a button? I would rather they not appear with the grey box around them but have them as simple text 'next' and 'back'. Apart from that it works beautifully!

All the best

S
samslystone is offline   Reply With Quote
Old 12-15-2012, 05:27 PM   PM User | #5
samslystone
New Coder

 
Join Date: Dec 2011
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
samslystone is an unknown quantity at this point
I would like it to look like this:

www.catherinehyland.co.uk/2012/work/work.html

S
samslystone is offline   Reply With Quote
Old 12-18-2012, 12:18 PM   PM User | #6
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,354
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Code:
  <p id="cf7_controls">
    <a class="clo" id="bak" >back</a><!-- any element other than a span -->
    <span class="selected">01</span>
    <span>02</span>
    <span>03</span>
    <span>04 </span>
    <span>05 </span>
    <span>06 </span>
    <span>07 </span>
    <a class="clo" id="nxt" >next</a> <!-- any element other than a span -->
        </p>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is online now   Reply With Quote
Old 12-18-2012, 09:50 PM   PM User | #7
samslystone
New Coder

 
Join Date: Dec 2011
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
samslystone is an unknown quantity at this point
Thanks again Vic!
samslystone is offline   Reply With Quote
Reply

Bookmarks

Tags
jquery, next previous, slideshow

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:21 AM.


Advertisement
Log in to turn off these ads.