wordpress - jQuery TypeError .offset is undefined -


have been trying resolve issue many hours , cant figure out.

the environment wordpress using smooth scroll function smooth scroll when select link on 1 page location on page.

the error getting is...

typeerror: $(...).offset(...) undefined

the offending line of code is...

  scrolltop: $(elem).offset().top - headerheight 

my entire function is

jquery(document).ready(function($) {  var headerheight = $('#header-wrap').height(); //when header position fixed  $('a').click(function(){     var hashele = $(this).attr('href').split('#');     if (hashele.length > 1) {         if (hashele[1] == 'top') {             $('body, html').animate({                 scrolltop: 0             },800);         } else {         jquery('body, html').animate({             scrolltop: $('#'+ hashele[1]).offset().top - headerheight         },800);         }     }; }) // find element url hashname = window.location.hash.replace('#', ''); elem = $('#' + hashname); if(hashname.length > 1) {     if(hashname == 'top') {     $('body, html').animate({             scrolltop: 0         },500);      } else {      $('body, html').animate({             scrolltop: $(elem).offset().top - headerheight         },800);  } };   }); 

i going crazy here, code works fine creating conflict woocommerce , not throw error. can tell me why causing trouble, sorry newbi question!

i may have found out problem:

  • the script works fine
  • the hash wrong!

you said have ##location in url string. if use:

window.location.hash 

it won't return anything. right hash should #location, different ##location.

if hardcode hash in url , try again you'll see works. if doesn't work, have script acting before causes (but don't think if you're following link, should worng)

to try out, change ##location #top (or thing according page elements)


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -