-1

I am using this jsfiddle: jsfiddle

In my site, I am getting the following error: Uncaught TypeError: Cannot read property 'top' of undefined

The line where it breaks of the jsfiddle:

var sidebarTop = $sidebar.position().top;

What could be the reason?


Just to give an idea of what I am trying to solve. I have a div in top of page, and set its position to fixed. When user scroll to the bottom of page, this div overlaps with the footer. I need to to stop (stick) this div in some place and does not go more to the bottom once it passes some point

Husanoo
  • 23
  • 6
  • 1
    when it's breaking ? – Nalin Aggarwal Aug 23 '16 at 18:22
  • it breaks on page load – Husanoo Aug 23 '16 at 18:26
  • Just to give an idea of what I am trying to solve. I have a div in top of page, and set its position to fixed. When user scroll to the bottom of page, this div overlaps with the footer. I need to to stop (stick) this div in some place and does not go more to the bottom once it passes some point. – Husanoo Aug 23 '16 at 18:29

1 Answers1

0

It's not breaking on either your jsfiddle or on my side. There might be possibility that you write your js script before the html is loaded. so try to write the js/jquery code at the end after your html page.

Refferences JavaScript on the bottom of the page?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Nalin Aggarwal
  • 886
  • 5
  • 8
  • Thanks Nalin. For some reason, I am not getting the error but code is not doing what it is supposed to do. The div does not get sticky. – Husanoo Aug 23 '16 at 18:45
  • the red div should be sticky ? @user2954449 – Nalin Aggarwal Aug 23 '16 at 18:58
  • The yerllow div should be sticky. And should not overlap the footer. – Husanoo Aug 23 '16 at 19:16
  • 1
    It's working fine.it's not overlapping. I added upto 12 textboxces, stil no effect with scrolling on minimum screen or larger. @user2954449 – Nalin Aggarwal Aug 23 '16 at 19:22
  • Please edit the externally hosted code into the post; doing so will make sure it remains useful even if the link breaks. My script [is not allowed to do this](https://meta.stackoverflow.com/a/344512/4751173) because of potential licensing problems. – Glorfindel Jan 13 '22 at 09:01