jquery - jquery中的滚动元素

标签 jquery

我有这个输入元素:

<input type="text" class="text field" value="" id="subject" name="subject">

对于按钮提交:

<input type="submit" class="submit" id="submit" name="submit" value="Ok, Done."> 

然后我还有一些其他元素,例如其他文本输入、文本区域等。

当用户单击带有 #subject 的输入时,页面应该滚动到页面的最后一个元素,并带有漂亮的动画。它应该滚动到底部而不是顶部。

页面的最后一项是带有#submit的提交按钮:

动画不应该太快并且应该流畅。

我正在运行最新的 jQuery 版本。我更喜欢不安装任何插件,而是使用默认的 jQuery 功能来实现此目的。

$(文档).ready(函数(){ $("#click").click(函数(){ $('html, 正文') }); }); 测试
测试2 点我

最佳答案

你可以尝试这样的事情。我已绑定(bind)focusclick事件,根据您的需要更新

$("#subject").on('focus click',function() {
    $('html, body').animate({
        scrollTop: $("#submit").offset().top
    }, 3500);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="text field" value="" id="subject" name="subject" />
<div class="div">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus 
     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus
       Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus
</div>
<input type="submit" class="submit" id="submit" name="submit" value="Ok, Done."/> 

关于jquery - jquery中的滚动元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51490932/

相关文章:

javascript - .Net Core PartialView 中的分页

javascript - 过渡列表项滚动 - HTML

javascript - IE7 CSS 问题 : cannot get correct span width

javascript - 如何将 jQuery 数据变量放入按钮而不是 div 中

javascript - 如何用字符分隔返回结果?

javascript - if 语句的多个简写?

javascript - 通过 npm 安装的包但它没有显示在文件夹中

javascript - Jquery - cookie 将过期日期设置为 1 天

jquery - val() 在迭代选择集合时失败 (jquery)

javascript - javascript输入错误的意外结束