0

I created a portfolio in Wordpress with the posts that open directly on the same page. Has been difficult, but I managed - following these steps - to make everything work... or almost.

What I want now is to make sure that, when the user clicks on an element, the page scroll to top to view the product details. I tried in all ways without success :(

This is the website: http://www.grafichepioppi.it/category/portfolio/

This is my code:

$(document).ready(function(){

$.ajaxSetup({
    cache:true, 
    async: true, 
    complete:function(){
        $('body,html').animate({scrollTop: 0}, 800);
   }});

$("a.link-portfolio").click(function(){

    var post_url = $(this).attr("href");
    var post_id = $(this).attr("rel");

    $("#portfolio-featured").html("<div class='loading-ajax'></div>").fadeIn(500);


     $("#portfolio-featured").load(post_url, function() {

    $('.portfolio-featured').show( 4000 );  
});

window.location.hash = post_id;

return false;
    });
});

Any ideas on how can I do that?

Community
  • 1
  • 1
nathinah
  • 1
  • 2
  • Well... then move the `$('body,html').animate({scrollTop: 0}, 800);` from `$.ajaxSetup({...})` to `$("a.link-portfolio").click(..)` – Bud Damyanov May 08 '14 at 11:05
  • I tried, but it doesn't work. The Chrome's console gives no errors, I can't figure out where is the mistake – nathinah May 08 '14 at 12:27

1 Answers1

0

Does this help?

     $("#portfolio-featured").load(post_url, function() {
       $('.portfolio-featured').show( 4000 );  
       $("html, body").animate({  
           scrollTop: $(this).offset().top - 300 }, 400); //to top
     });
shubhra
  • 772
  • 10
  • 26