Scroll to top when clicking on the navigation links

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Scroll to top when clicking on the navigation links

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #16870
    art2media
    art2media
    Participant

    Hi there,

    I’m trying to add a scroll effect. I have isotopic results and navigation active. It looks like in the screenshot. if I click on a page it should scroll up.

    I tried this:

    jQuery(document).ready(function( $ ) {
    	
    $('.asp_navigation li').on('click', function () {
    
    	$('html, body').animate({
    		scrollTop: $('.asp_shortcodes_container').offset().top
    	}, 300, 'linear');
    });
    	
    });

    But without effect. It doesn’t even add event listeners.
    Can you tell me if this is possible and if I’m missing an easy click in the plugin settings?

    Best regards,
    Simon

    Attachments:
    You must be logged in to view attached files.
    #16872
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Simon,

    Your code looks okay, but I would recommend a slightly different approach. If the event handler does not attach, the code might not be positioned correctly – or the event handler gets detached, as the results are dynamically changing.

    I would suggest something like this:

    Add this custom code to the functions.php in your theme/child theme directory (copy from line 3 only!). Before editing, please make sure to have a full site back-up just in case!

    This appears to be working on my end. The jQuery ‘on’ handler is better attached to the results div, as the results content is constantly changing, and the handler can get detached on dynamically changing elements.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #16873
    art2media
    art2media
    Participant

    Hi there,

    thank you, that works exactly as needed!

    Best regards,
    Simon

    #16874
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.