javascript - Smooth jScrollPane scrollbar length adjustment with dynamic content -


some of webpages contain several text elements expand , collapse jquery "accordion" effect:

function show_panel(num) {     jquery('div.panel').hide();     jquery('#a' + num).slidetoggle("slow"); }  function hide_panel(num) {     jquery('div.panel').show();     jquery('#a' + num).slidetoggle("slow"); } 

this causes window size change jscrollpane has reinitialized, change length of scrollbar. achieve smooth length adjustment of scrollbar, set "autoreinitialise" option "true" , "autoreinitialisedelay" "40" ms:

$(document).ready(function () { var win = $(window); // full body scroll var isresizing = false; win.bind(     'resize',  function () {     if (!isresizing) {         isresizing = true;         var container = $('#content');         // temporarily make container tiny doesn't influence         // calculation of size of document         container.css({             'width': 1,                 'height': 1         });         // make size of window...         container.css({             'width': win.width(),                 'height': win.height()         });         isresizing = false;         container.jscrollpane({             showarrows: false,             autoreinitialise: true,             autoreinitialisedelay: 40         });     } }).trigger('resize');  // workaround known opera issue breaks demo (see // http://jscrollpane.kelvinluck.com/known_issues.html#opera-scrollbar ) $('body').css('overflow', 'hidden');  // ie calculates width incorrectly first time round (it // doesn't count space used native scrollbar) // re-trigger if necessary. if ($('#content').width() != win.width()) {     win.trigger('resize'); }  }); 

the effect ok, on cost of high cpu usage makes fan go wild.

this jsfiddle shows settings , effect: http://jsfiddle.net/vvxvz/

here's example page (in fact it's iframe within webpage shown): http://www.sicily-cottage.net/zagaraenausfluege.htm

is there possibility achieve same "smooth" transition of scrollbar length without using "autoreinitialise" option, maybe additional script, modification of jscrollpane.js, or css animation of scrollbar , calling reinitialise manually?

i'm absolutely useless @ javascript appreciated.

there no need initialise jscrollpane on content everytime window resized. should once - on $(document).ready(). also, there no need in using autoreinitialize if content staic. should reinitialise jscrollpane update scrollbar size when slideup/slidedown 1 of container or on window.resize. so, code become less , more beautiful :)

function togglepanel(num) {     var jsp = $('#content').data('jsp');     jquery('#a' + num).slidetoggle({         "duration": "slow",         "step": function(){             jsp.reinitialise();         }     });     return false; }  $(document).ready(function () {      var container = $('#content').jscrollpane({         showarrows: false,         autoreinitialise: false     });     var jsp = container.data('jsp');      $(window).on('resize', function(){         jsp.reinitialise();     });      // workaround known opera issue breaks demo (see     // http://jscrollpane.kelvinluck.com/known_issues.html#opera-scrollbar )     $('body').css('overflow', 'hidden');      // ie calculates width incorrectly first time round (it     // doesn't count space used native scrollbar)     // re-trigger if necessary.     if (container.width() != $(window).width()) {         jsp.reinitialise();     }  }); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -