Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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
Javascript 若元素的左值为X,则停止函数_Javascript_Jquery - Fatal编程技术网

Javascript 若元素的左值为X,则停止函数

Javascript 若元素的左值为X,则停止函数,javascript,jquery,Javascript,Jquery,我试图使一个元素在旋转时从滚动条的左/右移动。当它们达到某个值时,我希望函数停止,我希望元素在鼠标滚动时移动小增量 我添加了一个IF statemenet,但它似乎阻止了我的函数工作?我还希望我的元素在停止时是正确的 我想不出最好的方法,所以下面是我的尝试,有人有想法吗 //如果“firstChart”左值为40,则停止滚动动画。 $(窗口).bind('scroll',function(){ var scrollTop=$(窗口).scrollTop(), chartContainer=($

我试图使一个元素在旋转时从滚动条的左/右移动。当它们达到某个值时,我希望函数停止,我希望元素在鼠标滚动时移动小增量

我添加了一个IF statemenet,但它似乎阻止了我的函数工作?我还希望我的元素在停止时是正确的

我想不出最好的方法,所以下面是我的尝试,有人有想法吗

//如果“firstChart”左值为40,则停止滚动动画。
$(窗口).bind('scroll',function(){
var scrollTop=$(窗口).scrollTop(),
chartContainer=($('.chartContainer').offset().top-scrollTop),
deg=-$(窗口).scrollTop()*5;
//如果我删除它,它会工作,但动画不会停止?

if(parseInt($('.firstChart').css('left'))您的
if
语句的结尾不正确,请使用
});
而不是
}

$(window).bind('scroll',function(){
    var scrollTop = $(window).scrollTop(),
    chartContainer = ($('.chartContainer').offset().top - scrollTop),
    deg = -$(window).scrollTop() * 5;

    var firstChartLeft = parseInt($('.firstChart').css('left'));
    //alert(firstChartLeft); /* uncomment for testing */
    if(firstChartLeft <= 40 || firstChartLeft==null){         
        $('.firstChart').css({
            'left': (chartContainer / 1) + "px",
            'transform': 'rotate(' + deg + 'deg)'
        });        
        $('.secondChart').css({
            'right': (chartContainer / 1) + "px",
            'transform': 'rotate(' + deg + 'deg)'
        });        
    }    
});
$(窗口).bind('scroll',function(){
var scrollTop=$(窗口).scrollTop(),
chartContainer=($('.chartContainer').offset().top-scrollTop),
deg=-$(窗口).scrollTop()*5;
var firstChartLeft=parseInt($('.firstChart').css('left'));
//警报(firstChartLeft);/*取消对测试的注释*/

if(firstChartLeft)$('.firstChart').css('left')的值是多少。我猜它是未定义的,因此会导致脚本失败。您在
if
语句上有语法错误。这将阻止它启动。即使在修复条件时,它也不会工作,因为只要您触摸滚动条,左值就超过40,因此不会发生任何事情->
$(window).bind('scroll',function(){
    var scrollTop = $(window).scrollTop(),
    chartContainer = ($('.chartContainer').offset().top - scrollTop),
    deg = -$(window).scrollTop() * 5;

    var firstChartLeft = parseInt($('.firstChart').css('left'));
    //alert(firstChartLeft); /* uncomment for testing */
    if(firstChartLeft <= 40 || firstChartLeft==null){         
        $('.firstChart').css({
            'left': (chartContainer / 1) + "px",
            'transform': 'rotate(' + deg + 'deg)'
        });        
        $('.secondChart').css({
            'right': (chartContainer / 1) + "px",
            'transform': 'rotate(' + deg + 'deg)'
        });        
    }    
});