Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset function on window resize

Tags:

jquery

restart

I'm using the SlimScroll plugin for my website.

I would like to reset/restart the slimscroll function on window resize, because the height and width should be changed according to the height and width of the #content_wrapper div.

I tried it trough several ways but nothing seemed to do the trick. Below my current code. Does anyone know how I can achieve this?

$('#content_wrapper').slimScroll({
    width: $('#content_wrapper').css({'width':(($(window).width())-240)+'px'}),
    height: $('#content_wrapper').css({'height':(($(window).height())-65)+'px'})
});

// scrollbar onresize resetten
$(window).resize(function(){    
    $('#content_wrapper').slimScroll({
        width: $('#content_wrapper').css({'width':(($(window).width())-240)+'px'}),
        height: $('#content_wrapper').css({'height':(($(window).height())-65)+'px'})
    });
});
like image 300
Jeffrey van Rossum Avatar asked Apr 16 '26 00:04

Jeffrey van Rossum


2 Answers

Just ran into this problem today and this works for me: when initializing slimScroll, it adds a div with class "slimScrollDiv". You can alter the height of this div and set it the same as your wrapper div...

  $(document).ready(function(){
    $('#scrollDiv').slimScroll({
      height: 'auto'
    });

    $(window).resize(function(){
      var h=$(window).height()-250;
      $('#scrollDiv').height(h);
      $('.slimScrollDiv').height(h);
    });
  });
like image 169
Alan Vercauteren Avatar answered Apr 18 '26 08:04

Alan Vercauteren


For version 0.5.0, replace the following:

// set up initial height
getBarHeight();

with:

$(window).resize(function() {
     getBarHeight();
     showBar();
});

I found this on http://dt.infolearn.com.gr/2012/03/jquery-slimscroll-refresh-on-window-resize/ and it worked for me.

like image 24
Phuong Vu Avatar answered Apr 18 '26 08:04

Phuong Vu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!