What is the error?

What is the error?

Hi.. could anyone tell me why this is doesn't work? the problem is when I open the page that at the beginning the .flex-viewport is not in the right place as when I resize or I reload the page... I premise that I'm not good with jquery and I'm trying to learn!


  1. var halfWindowHeight = jQuery( window ).height()/2;
  2. var halfViewportHeight = jQuery('#content .flexslider .slides li').height()/2;

  3. function putOnTheMiddle(){
  4.       var halfWindowHeight = jQuery( window ).height()/2;
  5.       var halfViewportHeight = jQuery('#content .flexslider .slides li').height()/2;
  6.       var result = parseFloat(halfWindowHeight) - parseFloat(halfViewportHeight);
  7.       var viewportNavHeight =  jQuery('.flex-control-nav li').height();
  8.       var paddingViewNav = jQuery('.flex-control-nav').css('padding-top');
  9.       var totViewNav = parseFloat(viewportNavHeight) + parseFloat(paddingViewNav);
  10.       jQuery('.flex-viewport').css("margin-top", result - parseFloat(totViewNav) + "px");
  11. }


  12. jQuery( window ).load(function(halfViewportHeight){
  13.        putOnTheMiddle()
  14. });

  15. jQuery( window ).resize(function(halfViewportHeight){
  16.        putOnTheMiddle()
  17. });