JS页面滚动不起作用

JS page scroll didn't work

本文关键字:不起作用 滚动 JS      更新时间:2023-09-26

我写了类似

$.ajax({
  type: 'POST',
  url: form.attr('action'),
  data: data,
  dataType: 'html',
  success: function(html){
    $(html).hide().appendTo(parent.find("[data-interactions]")).show().stop().animate({
        scrollTop: $(".vote_feedback_snippet:last-child").offset().top
    }, 1500,'easeInOutExpo');

当我单击发布按钮时,我在上面的代码中,它会在列表底部生成新的HTML片段我想要的:-当新的 Html 代码段出现时,它将仅向上滚动到该代码段

有人可以帮助我吗

尝试:

$(html).hide()
.appendTo(parent.find("[data-interactions]"))
.show('fast', function(){
  $('html, body').animate({
     scrollTop:  $(".vote_feedback_snippet:last-child").offset().top
  });
});

使用此插件:http://demos.flesler.com/jquery/scrollTo/

将允许您执行此操作:

$.scrollTo(".vote_feedback_snippet:last-child")

它总是对我有用。