Solved

scrollable page navigation

Posted on 2012-03-26
9
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 250 total points
ID: 37771358
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
ID: 37772887
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
ID: 37773473
no need to add or remove active, just click the li
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 5

Author Comment

by:Neil_Bradley
ID: 37773625
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37774976
I'll look in a few hours
0
 
LVL 75

Expert Comment

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

Expert Comment

by:Lalit Chandra
ID: 37775299
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
ID: 37775339
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
ID: 37778743
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 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