0
我的Laravel應用程序中有簡單的評論系統。問題在於有人提交評論頁面時正在重新加載頁面頂部。我希望該頁面返回用戶在原始評論所在的位置(保持滾動位置)。Laravel - 在郵件上保持滾動位置
這裏是負責徵求意見視圖的一部分:
@if ($signedIn)
{{ Form::open(['route' => ['comment_path', $status->id], 'class' => 'comments__create-form',]) }}
{{ Form::hidden('status_id', $status->id) }}
<div class="form-group">
{{ Form::textarea('body', null, ['class' => 'form-control', 'rows' => 1]) }}
</div>
{{ Form::close() }}
@endif
@unless ($status->comments->isEmpty())
<div class="comments">
@foreach ($status->comments as $comment)
@include ('statuses.partials.comment')
@endforeach
</div>
@endunless
這裏是jQuery的腳本,提交意見時,有人打ENTER
<script>
$('#flash-overlay-modal').modal();
$('.comments__create-form').on('keydown', function(e) {
if (e.keyCode == 13) {
e.preventDefault();
$(this).submit();
}
});
</script>
謝謝您的幫助!
即使您訪問網站上的不同頁面,上面的代碼仍會保持滾動位置。你可以修改'window.name + ='['+ location.pathname +'['+ $(window).scrollTop()。toString()+'['+ $(window).scrollLeft()。 toString();'AND' if(parts [parts.length - 3] == location.pathname){window.scrollTo(parseInt(parts [parts.length - 1]),parseInt(parts [parts.length - 2 ])); }' – 2016-04-21 17:12:21