0
I have the script to get back to TOPO. On the home page of the site, it works perfectly, however, on the internal pages it does not go up and presents the following error:
Uncaught Typeerror: Cannot read Property 'top' of Undefined
jQuery
$(document).ready(function () {
'use strict';
/* ========================================================================
Fullscreen burger menu
========================================================================== */
$(".menu-trigger, .mobilenav").click(function () {
$(".mobilenav").fadeToggle(500);
});
$(".menu-trigger, .mobilenav").click(function () {
$(".top-menu").toggleClass("top-animate");
$(".mid-menu").toggleClass("mid-animate");
$(".bottom-menu").toggleClass("bottom-animate");
});
/* ========================================================================
On click menu item animate to the section
========================================================================== */
$(".mobilenav li, .back-to-top").on('click', function() {
var target = $(this).data('rel');
var $target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing');
});
Error forwards the following line:
'scrollTop': $target.offset().top
Where I’d be wrong?
If you do
console.log($(target));
what it prints?– Miguel
main.js:26 Uncaught Typeerror: Cannot read Property 'top' of Undefined(Anonymous Function) @main.js:26jQuery.event.Dispatch @jquery-1.11.1.js:4641elemData.Handle @jquery-1.11.1.js:4309
– Sr. André Baill
Appears like this....
– Sr. André Baill
It is because this variable has nothing. Put the relevant part of your HTML
– Miguel
Hmmmm, you may not be finding your destination so I’ll try here!
– Sr. André Baill
I asked a question here, see if it can help you: http://answall.com/questions/30703/volta-homeda-p%C3%A1gina
– Marconi
It was the destination that was incorrect, so I put a <top id="top"></top> and it worked on all pages :) But obg anyway.
– Sr. André Baill
@Andrébaill, don’t invent element tags without proper implementation... if the goal is just to mark an anchor on your document, use the appropriate tag for this:
<a id="topo" href="#topo"></a>
– Leandro Angelo