0

Here is the existing script that I am using to filter some product details in my page. Currently, on filtering it loads a "loading" GIF animation. Instead of that I want it to scroll to the top using simple div id function. consider the page URL is http://websitename.com/folder/index.php, I am able to scroll to the top using

<a href="#top" class="nav-link">Go to top</a>

How can I automatically scroll to the top by changing this JQuery script ? I want to use this function instead of <div id="loading" style="" ></div>, how can I do that ?

<script>
$(document).ready(function(){

    filter_data();

    function filter_data()
    {
        $('.filter_data').html('<div id="loading" style="" ></div>');
        var action = 'fetch_data';
        var minimum_price = $('#hidden_minimum_price').val();
        var maximum_price = $('#hidden_maximum_price').val();
        var brand = get_filter('brand');
        var ram = get_filter('ram');
        var storage = get_filter('storage');
..... 
Shijil
  • 37
  • 4

3 Answers3

0

Thanks to @Bryn . $('.filter_data').html(window.scrollTo(1000, 0)); worked for me.

Shijil
  • 37
  • 4
0

You can try the following code:

$("a[href='#top']").on('click', function() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  return false;
});
Azhar
  • 693
  • 9
  • 22
0

Instead of

$('.filter_data').html('<div id="loading" style="" ></div>');

(or even $('.filter_data').html(window.scrollTo(1000, 0)); )

You should be able to just use

window.scrollTo(1000, 0);
Bryn Lewis
  • 580
  • 1
  • 5
  • 14