P
P
Pianista2016-06-28 22:39:09
JavaScript
Pianista, 2016-06-28 22:39:09

How to make ajax move to new comment in rails app?

I'm sorry for another stupid question, I'm just learning)
There are comments in the rails application for the post, they are created without refreshing the page.
here is my create.js.erb

$('#comments_<%= @post.id %>').append("<%= escape_javascript(render 'comments/comment', comment: @comment) %>");
$('#comment_title').val('');
$('#comment_text').val('');
$('#commentModal').modal('hide')

Everything works without problems.
But I would like to move to a new created comment and highlight the background of this comment. I can't figure out how to do it.
Probably something scrollTo or scrollTop, but nothing worked for me)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Demidenko, 2016-06-29
@Pianista

$("html, body").animate({scrollTop: $("#comment_<%= @comment.id %>").offset().top});

P
Pianista, 2016-06-29
@Pianista

$("#comment_<%= @comment.id %>").animate({scrollTop: $("#comment_<%= @comment.id %>").offset().top});

Does not work((

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question