page orientation with a dropdown menu

Asked

Viewed 87 times

-2

I have on a page of my website a menu dropdown with a list of rock bands. When you click on the menu it "drops" down showing the list by clicking on some band from that list it closes that menu dropdown and brings in a div below the information of the selected band. Only when selected a band from the bottom of this menu it does not raise the page to the beginning of the band information, it is in the middle of the information.

I would like to know how to make him go to the top of that information. Ah, I have tried to make an anchorage on menu and in info, but it won’t go to the anchoring part. If anyone wants to take a look at the menu in action the page is: http://fraturaexposta.esy.es/HTML/Paginas/dicas.php . Could someone help me?

1 answer

0

After a search I found the code responsible for the event.

$(document).ready(function(){
    $("#banda a").click(function( e ){
    e.preventDefault();
    var href = $( this ).attr('href');
    $("#div1").load( href +" #div1");
    });
});

First of all, this code doesn’t have to be inside the $(document).ready, because it is not executed immediately.

You want to go back to the beginning of the div after the .load, then you should add an anonymous function as a parameter in your event:

$("#div1").load( href +" #div1", function(){
    $(this).animate({ scrollTop: 0 }, "fast");
});

This will force the scroll to the beginning of the div using a quick animation.

  • in case only need to add this code in the event function file?

  • I tried to add this code of all that is way but it stops working the function or does nothing different. is that this information of the band he pulls from a div inside a page that works in the mobile version of the site, in case he pulls the div that has the information of the band into the div of the site for Desktop.

  • Yeah, I got that.

  • that code I sent you put in place of $('#div1').load(

  • Broder, I put it there but it didn’t work, he stopped calling the div who has the information of the band to the site and opening you direct page where ta this div.

  • i used the code like: $(Document). ready(Function(){ $("#band a"). click(Function( e ){ e. preventDefault(); var href = $( this ).attr('href'); $("#div1"). load( href +" #div1", Function(){ $(this). Animate({ scrollTop: 0 }, "fast"); }); }); $(Document). ready(Function(){ $("#a band"). click(Function(){ $("#panel"). Hide("slow"); }); ;});

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.