Jquery滚动到函数调用中
我有一段很好的Scrollto代码,它允许我平滑地设置锚文本的动画Jquery滚动到函数调用中,jquery,Jquery,我有一段很好的Scrollto代码,它允许我平滑地设置锚文本的动画 $(function(){ function scrollToAnchor(aid){ var aTag = $("a[name='"+ aid +"']"); $('html,body').animate({scrollTop: aTag.offset().top},'slow'); } $("#link").click(function() { scrollToAnchor('id
$(function(){
function scrollToAnchor(aid){
var aTag = $("a[name='"+ aid +"']");
$('html,body').animate({scrollTop: aTag.offset().top},'slow');
}
$("#link").click(function() {
scrollToAnchor('id123');
});
});
<a id="link" href="#">click me to scroll to 123</a>
<a name="123" id="123"/>Anchor
因为我在电话后硬编码了目的地。我刚刚删除了JS的函数方面,并直接编写了代码
$(document).ready(function() {
$("input[name$='item']").click(function() {
var req = $(this).val();
$.ajax({
cache: false,
type: "GET",
url: "information.php?id=" + req,
dataType: "html",
success: function(response){
$("#responsecontainer").html(response);
//alert(response);
}
});
var aTag = $("a[name='"+ "id123" +"']");
$('html,body').animate({scrollTop: aTag.offset().top},'slow');
});
});
锚定的代码是否来自ajax?嗨,Atul,不是。它在页面上是硬编码的。一旦Ajax完成了它的工作,它就是我想要它去的地方在
$(“#responsecontainer”).html(响应)之后代码>内部成功函数
$(document).ready(function() {
$("input[name$='item']").click(function() {
var req = $(this).val();
$.ajax({
cache: false,
type: "GET",
url: "information.php?id=" + req,
dataType: "html",
success: function(response){
$("#responsecontainer").html(response);
//alert(response);
}
});
var aTag = $("a[name='"+ "id123" +"']");
$('html,body').animate({scrollTop: aTag.offset().top},'slow');
});
});