简体   繁体   English

jQuery 动画在输入事件侦听器中不起作用

[英]jQuery animate not working inside input event listener

I have a simple html page with one text box.我有一个带有一个文本框的简单 html 页面。 When it is clicked I want the page to scroll down.单击它时,我希望页面向下滚动。 So I put an event listener on the text box and in it I use animate for the scrolling.所以我在文本框中放置了一个事件侦听器,并在其中使用 animate 进行滚动。 But when I run this the scrolling is not happening...但是当我运行它时,滚动没有发生......

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script >
        $(document).ready(function() {
                    $("input").focus(function() {
                      $("html, body").animate(scrollTop: $(window).scrollTop() + 400);
                    })
            });
   </script>
</head>
<body>
<input type="text">

你忘了{ }

$("html, body").animate({scrollTop: $(window).scrollTop() + 400} , 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM