Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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/3/html/75.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
滚动到Horizontall问题,timeline jquery_Jquery_Html_Css_Timeline - Fatal编程技术网

滚动到Horizontall问题,timeline jquery

滚动到Horizontall问题,timeline jquery,jquery,html,css,timeline,Jquery,Html,Css,Timeline,我的scrollTo遇到问题,它似乎没有滚动到水平定位点 看起来锚点的位置正在自行重置 $(“.jq时间线标题”)。单击(函数(e){ 如果($(窗口).width()

我的scrollTo遇到问题,它似乎没有滚动到水平定位点

看起来锚点的位置正在自行重置

$(“.jq时间线标题”)。单击(函数(e){
如果($(窗口).width()<768){
$(this.next().toggle();
}
});
$('.jq scrollto').bind('click',函数(事件){
console.log($($(this.attr('href')).offset().left)
$('.jq scrollto').removeClass('active');
$(this.addClass('active');
$('.jq timeline inner').stop().animate({
滚动左:$($(this.attr('href')).offset().left
}, 1000);
consoleLog();
event.preventDefault();
});
变量x、y、上、左、下;
$(“.jq时间线内部”).mousedown(函数(e){
e、 预防默认值();
向下=真;
x=e.pageX;
y=e.pageY;
top=$(this.scrollTop();
left=$(this.scrollLeft();
});
$(“.jq时间线内部”).mousemove(函数(e){
如果(向下){
var newX=e.pageX;
var newY=e.pageY;
//log(y+,“+newY+”,“+top+”,“+(top+(newY-y)));
$(this).scrollTop(top-newY+y);
$(this.scrollLeft(left-newX+x);
}
});
$(“.jq时间线内部”).mouseup(函数(e){
向下=假;
});

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();
    });

检查

您好,非常感谢您的帮助,请您再给我解释一下为什么我们要再次调用scrolleft好吗?
$($(this).attr('href')).offset()。左
在滚动时将设置为0。因此,我们必须在滚动后添加当前位置,即
$('.jq timeline internal')。滚动左()
滚动后您可以在此处获得它<代码>1000,函数(){console.log($('.jq timeline-inner').scrollLeft();})检查
 $('.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();
    });