gpt4 book ai didi

javascript - 如何在ajax调用成功时在div之间导航

转载 作者:行者123 更新时间:2023-11-29 19:25:40 27 4
gpt4 key购买 nike

我正在开发单页应用程序,我一直在 div 之间导航,这很简单,但我想用 ajax 来完成....

I wanted to do something like When "success" function called then it should send/scroll user view to another div..... I already tried the .animate but failed....

任何类型的帮助或引用将不胜感激

<div id="SecondInfo"></div>
<script>
$("#btnSubmit").click(function () {
var FirstName = $('#FirstName').val();
$.ajax({
type: "POST",
url: '@Url.Action("Submit", "Home")',
dataType: "JSon",
data: { "FirstName": FirstName},
success: function (data) {
console.log(data);
$("#SecondInfo").animate({ scrollTop: "0px" });
},
error: console.log("it did not work"),
});
});
</script>

最佳答案

animate() 中使用 scrollTop() 并设置您想要聚焦的元素的偏移量,这里是代码的一部分。

$('html,body').animate({scrollTop: $('#second').offset().top}, 200, function() {
//next code
});

演示 JsFIddle Scroll animate

关于javascript - 如何在ajax调用成功时在div之间导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30909961/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com