Miniscroll-JS icon indicating copy to clipboard operation
Miniscroll-JS copied to clipboard

Performance

Open vsekelj opened this issue 10 years ago • 4 comments

I went through probably 10 different custom scrollbars plugins and let me tell you - yours was the best/easiest one to setup with my (pretty complex) page. Great job!

However - there are a few problems with it - performance the worst one. For example - should it really update the DOM/CSS every 10 milliseconds even if the user is not doing anything and the scroll is not changing?

If yes - why not optimise it a bit - for example if the values are the same as the last DOM/CSS update - they don't really need to be updated/overwritten again.

vsekelj avatar Feb 20 '15 14:02 vsekelj

excellent idea, I will try to implement it as soon as possible, in fact this was a problem that bothered me a lot, thank you and if you have more ideas to help feel free

rogerluiz avatar Feb 20 '15 14:02 rogerluiz

It should be an easy fix to try - I just had a minute and tried something like this:

    var last = []; 

    Miniscroll[prototype].css = function (element, arguments) {

        for (var prop in arguments) {

            if (last[element.className+prop] != arguments[prop]) {

                if (prop === 'opacity') {
                    element.style.filter = 'alpha(opacity=' + (arguments[prop] * 100) + ')';
                    element.style.KhtmlOpacity = arguments[prop];
                    element.style.MozOpacity = arguments[prop];
                    element.style.opacity = arguments[prop];
                } else {                    
                    element.style[prop] = arguments[prop];
                }

                last[element.className+prop] = arguments[prop];

            }

        }
    };

But that with class names ugly/dirty of course :) You'll probably want to do a better element test i.e. a virtual DOM retainer object. Plus you might want to look into possibly replacing setInterval with requestAnimationFrame (or a good requestAnimationFrame/setInterval shim for older browsers).

vsekelj avatar Feb 20 '15 14:02 vsekelj

yes I was wanting to do that already some time. this is an excellent way to do this

rogerluiz avatar Feb 20 '15 14:02 rogerluiz

i start to developer the new version of the miniscroll and i will add this to the code https://github.com/rogerluiz/Miniscroll-JS/tree/dev

rogerluiz avatar Aug 25 '15 15:08 rogerluiz