Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery滑块进行可滚动分页时获得正确的开始位置_Jquery_Jquery Ui_Slider - Fatal编程技术网

使用jQuery滑块进行可滚动分页时获得正确的开始位置

使用jQuery滑块进行可滚动分页时获得正确的开始位置,jquery,jquery-ui,slider,Jquery,Jquery Ui,Slider,我正在构建一个脚本来处理很长的分页。为此,我使用jQuery滑块 我正在使用中的一些修改函数 这是目前为止的js代码。唯一缺少的是在加载脚本时将分页div移动到正确的位置(滑块移动)。在初始化时,我只想运行与用户使用滑块时运行的相同的函数 // Calculate total width var totalWidth = 0; $('.pageItem').each(function() { totalWidth += $(this).outerWidth

我正在构建一个脚本来处理很长的分页。为此,我使用jQuery滑块

我正在使用中的一些修改函数

这是目前为止的js代码。唯一缺少的是在加载脚本时将分页div移动到正确的位置(滑块移动)。在初始化时,我只想运行与用户使用滑块时运行的相同的函数

    // 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);

谢谢

我不知道我们是否使用相同的插件,但这是移动滑块的代码:

$('#content-slider').slider("moveTo", "-=1");
$('#content-scroll').stop();

我正在使用jQueryUI滑块。我不明白您的代码将如何帮助我…我也知道您需要在页面加载时将滑块移动到指定位置,因此您需要使用:$(document).ready(function(){$('#content slider').slider(“moveTo”,“-=1”);$('#content scroll').stop());数字1是移动滑块的位置,因此,如果您有100个页面,并且您在第40页,并且滑块由100个单位(最大值)组成,则您将使用$(“#内容滑块”)。滑块(“移动到”,“+=40”);所以,您需要在页面上添加此代码,然后手动填充+=40变量。忘记告诉您用各自的ID替换内容滑块和内容滚动