views:

413

answers:

1

Hi!

I am building a script for handling very long paginations. For this I use jQuery slider.

I using some modified functions from here.

This is the js code so far. The only thing that is missing is the pagination div to move to the correct position (slider does) when the script loads. On initialization I just want to run the same function that runs when the user uses the slider.

    // Calculate total width
 var totalWidth = 0;
 $('.pageItem').each(function() {
  totalWidth += $(this).outerWidth(true);
 });

 // Total number of pages
 var totalPages = $('.pageItem').size();

 // Calculate current position ( starts counting at 0 )
 var currentPage = $('li').index($('.current')) + 1;

 // Scroll start position
 var scrollPosition = [currentPage / totalPages] * 100;

 $('#pagiMoreSlider').slider({
  change:   handleSliderChange,
  slide:   handleSliderChange,
  max:    100,
  value:   scrollPosition,
 });
 function handleSliderChange(e, ui){
  var maxScroll = $('#pagiMoreContent').attr('scrollWidth') - $('#pagiMoreContent').width();
  $('#pagiMoreContent').attr({
   scrollLeft: ui.value * (maxScroll / 100)
  });
 }

 // Set width pagiMore
 $('#pagiMore ul').width(totalWidth);

Thanks!

A: 

Well I dont know if we are using the same plugin but this is the code for moving the slider:

$('#content-slider').slider("moveTo", "-=1");
$('#content-scroll').stop();
dfilkovi
I am using the jQuery UI slider http://jqueryui.com/demos/slider/. I don't understand how your code will help me...
Fred Bergman
Well as I understand you need to move the slider on page load to a specified position, so you need to use:$(document).ready(function() {$('#content-slider').slider("moveTo", "-=1");$('#content-scroll').stop();});This number 1 is a position where to move your slider, so if you have 100 pages and you are on page 40, and slider is made with 100 units (max value) you will use $('#content-slider').slider("moveTo", "+=40");So you need to add this code on page and dinamicaly fill that +=40 variable.
dfilkovi
Forgot to tell you to replace content-slider and content-scroll with your respective ID-s
dfilkovi