albertogasparin/Optiscroll

Let's improved Optiscroll's CSS

henryruhs opened this issue · 6 comments

Hey Wilson, I really like your plugin but the CSS far from perfect :-)

Let me show my workover, maby you find it useful:

  1. Combined and ordered all definitions
  2. Switched from PX to REM
  3. Removed useless vtrack and htrack offset
  4. Improved transition delay out
  5. Moved the draggable area to vtrack and htrack

Suggestions:

  1. Use shorthand translateZ(0) to enable CSS performance
  2. Uncomment or remove the user-select block
  3. Run autoprefixer over your CSS, many vendor prefixes are outdated
  4. Add namespace to .htrack-on and .vtrack-on
  5. Consider a naming convention like: https://github.com/redaxmedia/ncss
/**
 * @tableofcontents
 *
 * 1. scrollbar
 *    1.1 horizontal and vertical
 *    1.2 track
 */

/* @section 1. scrollbar */

.optiscroll {
    position: relative;
    overflow: hidden;
}

.optiscroll-content {
    bottom: 0;
    left: 0;
    right: 0;
    overflow: auto;
    position: absolute;
    top: 0;
}

/* @section 1.1 horizontal and vertical */

.optiscroll-h {
    height: 0.25rem;
    left: 0.5rem;
}

.optiscroll-v {
    top: 0.5rem;
    width: 0.25rem;
}

.optiscroll-h, .optiscroll-v {
    bottom: 0.5rem;
    opacity: 0;
    position: absolute;
    right: 0.5rem;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    transition: opacity 0.2s ease-out 0.8s;
}

/* hover */

.htrack-on:hover .optiscroll-h, .vtrack-on:hover .optiscroll-v {
    opacity: 1;
    transition: opacity 0.2s ease-out;
}

/* @section 1.2 track */

.optiscroll-htrack, .optiscroll-vtrack {
    background: #aaa;
    cursor: pointer;
    left: 0;
    position: absolute;
    top: 0;
}

.optiscroll-htrack {
    height: 100%;
}

.optiscroll-vtrack {
    width: 100%;
}

.optiscroll-htrack:active, .optiscroll-vtrack:active {
    background: #999;;
}

/* draggable area */

.optiscroll-htrack:before, .optiscroll-vtrack:before {
    content: '';
    position: absolute;
    top: -0.5rem;
    left: -0.5rem;
    bottom: -0.5rem;
    right: -0.5rem;
}

Keep on the good work!

Yes, you are right. When I first wrote that style it was more an example than a proper boilerplate.
It needs some refactoring 😉

Another idea for this project is use BEM, what you think @albertogasparin ?


Pull request #12

Well, while I agree on the need of some CSS improvements (following @redaxmedia suggestions), I'm still not convinced on using one explicit methodology. On some projects I use BEM, on some others SMACSS or BLISS or "name one", so the plugin will never be compliant with all of them. And customizing each class name individually is overkill.
What can be easily done, however, is tweaking the classPrefix parameter to contain also the separator, so you can decide whenever you prefer a single dash, a double underscore or something else.
It will add an additional level of customization without increasing complexity.

Yes, that's what I was thinking of. I will add a $classPrefix variable in the SCSS file so people can customize both js and css.

Version 2.0 is now out with CSS being mostly rewritten. I'm going to close this as most of the suggestions have been implemented. If further discussion is needed, please open a new issue.
Thanks