jQuery动画在输入事件监听器中无法工作。

问题描述 投票:0回答:1

我有一个简单的html页面,有一个文本框。当它被点击时,我想让页面向下滚动。所以我在文本框上设置了一个事件监听器,并在其中使用动画来滚动。但是当我运行这个程序时,滚动没有发生......

<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">

javascript html jquery event-listener jquery-events
1个回答
3
投票

你忘了 { }

$("html, body").animate({scrollTop: $(window).scrollTop() + 400} , 1000);
© www.soinside.com 2019 - 2024. All rights reserved.