Solved

scrollable page navigation

Posted on 2012-03-26
9
332 Views
Last Modified: 2012-03-28
The following is a link to a page containing a jquery scroller http://gromit.utopia.co.nz/~thebette/play/slider.html.
The code was taken from this website http://musca.se/full-window-width-jquery-tools-content-slider-demo/.

I am trying to modify the script to allow me to change the default first screen. At the moment the page opens on slide 1. What I need to be able to open the page on an alternate slide (so I can navigate direct to a particular item from an alternate page).
Assistance appreciated.
Cheers,
N
0
Comment
Question by:Neil_Bradley
  • 5
  • 2
  • 2
9 Comments
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 250 total points
Comment Utility
This code wil scroll to the slide number given as

#1
#2
#3
after the url

$(document).ready(function() {
  var page = parseInt(location.hash.substring(1),10); 
  if (isNaN(page)) page=1;
  $("#navigation li:nth-child(page)").trigger("click");
});

Open in new window

0
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 250 total points
Comment Utility
you can try the code below

$(function() {
         var defaultPageNumber =1
         var ctlPager = $("#navigation li").removeClass("active");
         $.each(ctlPager,function(i,j) {
             if((i+1) == defaultPageNumber )
            {  
                  $(this).addClass("active").click(); return false;
             }
        });
});

Just change the value of defaultPageNumber  to set the default page you want;

Hope this will solve your issue.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
no need to add or remove active, just click the li
0
 
LVL 5

Author Comment

by:Neil_Bradley
Comment Utility
Reply to mplungjan.
I have implemented your code. A link to your slider test page can be found here: http://gromit.utopia.co.nz/~thebette/play/linkTo.html
As you will see, no matter which link I click on the slider page opens, then scrolls to the last item. Can you have a look and see if there is anything wrong with the way I have implemented you code?

Reply to Lalit-Chandra
You code works perfectly (here is the working page http://gromit.utopia.co.nz/~thebette/play/solution2.html).  If I wanted to modify your code so that:
1. The default page is set by the number after the # in the url. IE clicking to slider.html#2 from another page takes me directly to that item as opposed to slider.html#2 opening then scrolling.

To summarize. if I am on the slider page then the navigation should move the slider. If I click a link to the slider page (IE slider.html#2)  then the item clicked on should show by default as opposed to the page opening then the slider sliding to the item.
Thanks for your input.
N
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
I'll look in a few hours
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
I do not see my code at all at the link you gave
0
 
LVL 7

Expert Comment

by:Lalit Chandra
Comment Utility
hi  Neil_Bradley,

As your this post question

Scroll Page Navigation
I am trying to modify the script to allow me to change the default first screen. At the moment the page opens on slide 1.

has been solved.So,please close this post,as now your question is now moving in another direction and you want the solution.
So, Please close the post and start a new post of this, as there is only one question per post.

Hope you understand.

Thanks
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Lalit-Chandra - there is nothing new in the post by Neil.

the code I posted will do exactly what has been asked.
If you change

http://gromit.utopia.co.nz/~thebette/play/slider.html

from

// Scrollable and navigator plugin settings.
$("#slider").scrollable({ easing: 'easeOutQuad', speed: 900, circular: true }).navigator({ navi: '#navigation' });

Open in new window


to

// Scrollable and navigator plugin settings.
$("#slider").scrollable({ easing: 'easeOutQuad', speed: 900, circular: true }).navigator({ navi: '#navigation' });

var page = parseInt(location.hash.substring(1),10); 
if (isNaN(page)) page=1;
$("#navigation li:nth-child(page)").trigger("click");

Open in new window


it should works as expected with a link to

http://gromit.utopia.co.nz/~thebette/play/slider.html#1
http://gromit.utopia.co.nz/~thebette/play/slider.html#2
http://gromit.utopia.co.nz/~thebette/play/slider.html#3

going to slide 1, 2 and 3
0
 
LVL 5

Author Closing Comment

by:Neil_Bradley
Comment Utility
Thank you to both mplungjan and Lalit-Chandra for your submissions. The final solution came from combining both suggestions. I realize that that my question was quite complex so I am sure that I will soon be posting soon with a spin of question.
Thanks again.
Cheers,
N

Final solution:
 var page = parseInt(location.hash.substring(1),10);  
   var ctlPager = $("#navigation li");
         $.each(ctlPager,function(i,j) {
             if((i+1) == page )
            {  
                  $(this).addClass("active").click(); return false;
             }
        });
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now