滚动到Horizo​​ntall问题,时间轴jquery

时间:2015-05-19 03:19:40

标签: jquery html css timeline

我遇到了我的scrollTo问题,它似乎没有滚动到水平锚点。

看起来锚点的位置正在重置。

http://jsfiddle.net/6nqv78wp/7/

$(".jq-timeline-header").click(function (e) {
    if ($(window).width() < 768) {
        $(this).next().toggle();
    }
});


$('.jq-scrollto').bind('click', function (event) {
    console.log($($(this).attr('href')).offset().left)
    $('.jq-scrollto').removeClass('active');
    $(this).addClass('active');
    $('.jq-timeline-inner').stop().animate({
        scrollLeft: $($(this).attr('href')).offset().left
    }, 1000);
    consoleLog();
    event.preventDefault();
});

var x, y, top, left, down;

$(".jq-timeline-inner").mousedown(function (e) {
    e.preventDefault();
    down = true;
    x = e.pageX;
    y = e.pageY;
    top = $(this).scrollTop();
    left = $(this).scrollLeft();
});

$(".jq-timeline-inner").mousemove(function (e) {
    if (down) {
        var newX = e.pageX;
        var newY = e.pageY;

        //console.log(y+", "+newY+", "+top+", "+(top+(newY-y)));

        $(this).scrollTop(top - newY + y);
        $(this).scrollLeft(left - newX + x);
    }
});

$(".jq-timeline-inner").mouseup(function (e) {
    down = false;
});

1 个答案:

答案 0 :(得分:2)

JQuery中的更改将解决您的问题:

 $('.jq-scrollto').bind('click', function (event) {

        console.log($($(this).attr('href')).offset().left);

        $('.jq-scrollto').removeClass('active');
        $(this).addClass('active');


        $('.jq-timeline-inner').stop().animate({
            scrollLeft:  $($(this).attr('href')).offset().left + $('.jq-timeline-inner').scrollLeft()  //Changes here.
        }, 1000);
        event.preventDefault();
    });

检查Fiddle Here.