jquery - how to make .top and .offset work together -


i'm having problems solving why jquery being ignored. below jquery:

$(document).ready(function() { var $root = $('html, body '); $('a').click(function(e) {     var href = $.attr(this, 'href');     $root.animate({         scrolltop: $(href).offset.top     }, 500, function () {         window.location.hash = href;     });     return false; }); 

this jquery trying nicely scroll part of page works if use .offset('top') throws out error :

uncaught typeerror: cannot use 'in' operator search 'using' in top

which has made jquery jump instead of scroll nicely.

the rest of jquery code:

// responsive menu  $(function() {     var pull        = $('#pull');         menu        = $('nav ul');         menuheight  = menu.height();      $(pull).on('click', function(e) {         e.preventdefault();         menu.slidetoggle();     });      $(window).resize(function(){         var w = $(window).width();         if(w > 320 && menu.is(':hidden')) {             menu.removeattr('style');         }     }); });  

});

has experienced before , have found solution?

you trying property top of function offset:

$(href).offset.top 

jquery objects have method .offset(), result of running has property .top. perhaps that's want use?

$(href).offset().top 

i have investigated error message , pretty clear happens in the setoffset call in jquery. seems somewhere offset function being called parameter "top", incorrect.

without having of code can't debug further, please check scrollto parameter spelled out correctly , error happens on line in code.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -