Jquery jscrollpane plugin error

2019-07-21 07:57发布

问题:

I get this error when I try and implement jSrollpane in Safari 4:

TypeError: Result of expression '$drag[0]' [undefined] is not an object.

Then i get this error when i try the same thing in Chrome:

Uncaught TypeError: Cannot read property 'offsetHeight' of undefined

But why? it works fine in FF.

Any ideas?

回答1:

It appears that jQuery does not manage to resolve the child selector (“parent > child”), thus both "$track" and "$drag" are set to undefined values:

$track = $('>.jScrollPaneTrack', $container);
$drag = $('>.jScrollPaneTrack .jScrollPaneDrag', $container);

As a result, the scrollbar does not initialize, and simply does nothing Replacing the previous lines with a "dumbed down" version fixes the issue:

$track = $container.children(".jScrollPaneTrack");
$drag = $track.children(".jScrollPaneDrag");