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?

2
  • Well... then move the $('body,html').animate({scrollTop: 0}, 800); from $.ajaxSetup({...}) to $("a.link-portfolio").click(..) Commented May 8, 2014 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 Commented May 8, 2014 at 12:27

1 Answer 1

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
     });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.