2

I have a JS code like this below:

$(window).resize(function () {
    if ($('.scrollbar-y').length) {
        $('.scrollbar-y').tinyscrollbar_update('relative');
    }
    if ($('.scrollbar-x').length) {
        $('.scrollbar-x').tinyscrollbar_update('top');
    }
});

at $('.scrollbar-y').tinyscrollbar_update('relative'); this line it's showing

Uncaught TypeError: Cannot read property 'update' of undefined

So How to check TinyScrollBar is initialized or not with .scrollbar-y div ?

If I write:

$(window).resize(function () {
    if ($('.scrollbar-y').length) {
        $('.scrollbar-y').tinyscrollbar();
        $('.scrollbar-y').tinyscrollbar_update('relative');
    }
    if ($('.scrollbar-x').length) {
        $('.scrollbar-x').tinyscrollbar();
        $('.scrollbar-x').tinyscrollbar_update('top');
    }
});

It's showing

Uncaught TypeError: Cannot read property 'offsetHeight' of undefined

Rana Ghosh
  • 4,514
  • 5
  • 23
  • 40
  • Have you tinyscrollbar-ed it already? You can't update it if you haven't made it into a tiny scrollbar yet. – Dave Newton Dec 19 '16 at 15:16
  • @DaveNewton please check the edited version. – Rana Ghosh Dec 19 '16 at 15:19
  • Don't forget that a selector in jQuery can return zero, one or more elements. Especially if the selector is a class. Try to change your code by : `$('.scrollbar-y').each(function() { $(this).tinyscrollbar_update('relative'); });` – Fefux Dec 19 '16 at 15:24
  • @Fefux yes but i want that if with ".scrollbar-y" div tinyscrollbar is initialized or associated then only then scrollbar update will called. – Rana Ghosh Dec 20 '16 at 07:35

0 Answers0