auroralabs's avatar

Laravel Pagination Fragment Question

Hi,

I have a section in my blade template for pagination that appends an ID to the URL to stop the view jumping to the top of the page. I have added the fragment block however as soon as this is added pagination no longer works.

<div class="col-12_sm-12_xs-12">
    {{ $rooms->fragment('property_rooms')->links() }}
</div>

The issue seems to be with Smooth Scrolling as I have a script that I use to navigate to sections of the page for property layouts. When i remove this script and recompile pagination start working again. Can anyone suggest a reason why this script would be affecting pagination and especially the fragment option?

(function() {
    $('a[href*="#"]').on('click', function(e) {
        e.preventDefault()

        $('html, body').animate(
            {
                scrollTop: $($(this).attr('href')).offset().top,
            },
            500,
            'linear'
        )
    })
}());
0 likes
3 replies
Snapey's avatar

So your URL correctly shows the #property_rooms ?

Have you tried it after adding a document.ready condition?

auroralabs's avatar

HI,

I can see the URL in the bar of the browsers with #property_rooms in it but it wont move off the initial page. Once the script is removed however it works as it should and goes to the second page and sits at the correct anchor point on the page.

auroralabs's avatar

Ahhh solved it I removed

e.preventDefault()

and its working!!

Please or to participate in this conversation.