There is a chat on yii2. In the chat, pjax is used to upload messages and change dialogs. There is a script that scrolls to the end of the message. One pjax widget is nested in another. (id different).
External pjax is updated when a dialog is selected and when a message is sent. Internal pjax is updated every 10 sec.
It looks like this:
... //внешний pjax <?php Pjax::begin([ 'id' => 'all-chat', 'timeout' => 5000, 'formSelector' => '.input_msg_write' ]) ?> ... //некоторый код ... <div class="msg_history"> //блок с сообщениями, который нужно пролистать вниз //внутренний pjax <?php Pjax::begin([ 'id' => 'list-messages', 'timeout' => 5000, 'enablePushState' => false, 'formSelector' => false, 'linkSelector' => false ]) ?> ... //тут сообщения которые обновляются раз в 10 сек ... <?php Pjax::end() ?> </div> ... //еще немного кода ... <?php Pjax::end() ?> ... It is necessary that the script that scrolls to the end of the message works only when the external pjax is updated, but does not work when the internal is updated.
I tried to write like this:
$('#all-chat').on('pjax:success',function () { scrollTopChat(); }) but then the messages are scrolled when updating any of the two pjaxes