Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.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 基于y轴激活动画_Javascript_Jquery_Html - Fatal编程技术网

Javascript 基于y轴激活动画

Javascript 基于y轴激活动画,javascript,jquery,html,Javascript,Jquery,Html,对不起,这个问题很初级。我只是不知道从哪里开始我希望得到一些提示 我需要启动一个动画,一旦用户在网页的某一部分。通过这样做,我能够找到坐标 $("body").click(function(event){ alert("this is the x coordinate: "+event.pageX); alert("this is the y coordinate: "+event.pageY); }); 有没有人能给我举个例子,说明当用户滚动到坐标y 1254时,动画开始了?

对不起,这个问题很初级。我只是不知道从哪里开始我希望得到一些提示

我需要启动一个动画,一旦用户在网页的某一部分。通过这样做,我能够找到坐标

$("body").click(function(event){
   alert("this is the x coordinate: "+event.pageX);
   alert("this is the y coordinate: "+event.pageY);

});
有没有人能给我举个例子,说明当用户滚动到坐标y 1254时,动画开始了? 我还找到了viewport.js,但文档中只显示了一个非常可怕的示例

这是我试着做的,但似乎根本不起作用

$(".second-image:in-viewport").css({marginLeft:'-999px'}).animate(
        {marginLeft:'0px'}, {duration:2000});

我似乎无法将console.log与viewport一起使用。

您需要检查页面滚动,然后在滚动时,检查您是否离页面顶部太远或某个元素是否可见

试试这个JSFIDLE: 缩小结果窗口,这样您就必须稍微滚动一下

以下是jQuery:

$(document).scroll(function () {
    if ($(window).scrollTop() >= 200) {
        $(".second-image").animate({
            marginLeft: '230px'
        });
    }
});

嗨,谢谢你这对我来说有点道理。我只是好奇,到底200是什么?你说scrollTop()>=200…这是…什么的位置?再次非常感谢你救了我的命:)200是窗口顶部上方的像素数。因此,如果向下滚动页面200像素,则$(window).scrollTop()等于或大于200。这可能有点帮助: