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');
.....
Thanks to @Bryn . $('.filter_data').html(window.scrollTo(1000, 0));
. $('.filter_data').html(window.scrollTo(1000, 0));
worked for me.
You can try the following code:
$("a[href='#top']").on('click', function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.