0

I have this site:

link

In the left column and there I found a menu

I want that to be aligned to the center menu ... I put a picture below to understand more clearly what I mean.

enter image description here

CODE JS:

function centerContent()
{
    var container = $('#secondary');
    var content = $('#primary-sidebar');
    var logo=$('#secondary h1:first-child');
    content.css("margin-top", (container.height()-logo.height()-content.height())/2);
}

Can you tell me please which is why it displays the menu too low? Calculation is wrong?

Thanks in advance!

cristi
  • 405
  • 3
  • 11
  • 1
    Why don't you make it with pure javascript? It's so easy: `#logo { position: absolute; top: 50%; transform: translateY(-50%); }` Note that `#logo` it's an selector example. See it works: https://jsfiddle.net/auww7cr9/ – Marcos Pérez Gude Aug 10 '15 at 08:40

1 Answers1

0

Yes, you can use $(window).height() for the window height and $(document).scrollTop() (space between document start and current scroll height) for calculating the middle position of the screen. Try this:

var middleHeight = $(document).scrollTop() + $(window).height() / 2.0;
Pouya Ataei
  • 1,959
  • 2
  • 19
  • 30