0

I implemented spectrum color picker. I'm trying to rotate the .alphaSlider 180 deg. Of course I can do it with CSS (using transform: rotate(180deg)), but that's sort of a hack, and, there will anyway be other problems. I want to do it using the JavaScript source file.

How can I edit the source file so that I can rotate 180 Deg the .alphaSlider?

Here's the relevant code:

Source: (Lines: 387-395)

draggable(alphaSlider, function (dragX, dragY, e) {
    currentAlpha = (dragX / alphaWidth);
    isEmpty = false;
    if (e.shiftKey) {
        currentAlpha = Math.round(currentAlpha * 10) / 10;
    }
    move();
}, dragStart, dragStop);

Source: (Lines: 1068 - 1073)

var t0 = e.originalEvent && e.originalEvent.touches && e.originalEvent.touches[0];
var pageX = t0 && t0.pageX || e.pageX;
var pageY = t0 && t0.pageY || e.pageY;

var dragX = Math.max(0, Math.min(pageX - offset.left, maxWidth));
var dragY = Math.max(0, Math.min(pageY - offset.top, maxHeight));
Horay
  • 1,388
  • 2
  • 19
  • 36
  • The question is pretty unclear here. Are you trying to rotate an HTML element *without* using CSS? If so I don't think that's possible. If an element is rendered in HTML then the only way to style/transform it is with CSS. What exactly is preventing you from doing a CSS transform? – jered Dec 14 '15 at 23:32
  • @JCD It sounds to me like he wants the alpha bar for the spectrum color picker library to show up vertical instead of horizontal. This is something that isn't exactly simple. I'm learning some Node.JS stuff and I'll be using this question as my first project. ;) – teynon Dec 14 '15 at 23:35
  • @Tom I'm Homered! :-) – Horay Dec 15 '15 at 00:03
  • http://stackoverflow.com/questions/15935837/how-to-display-a-range-input-slider-vertically ? – Mike 'Pomax' Kamermans Dec 15 '15 at 00:38
  • @Mike'Pomax'Kamermans This isn't a uislider, it was custom made. – Horay Dec 15 '15 at 00:43

1 Answers1

1

BOOM! Done. See jsfiddle. (Snippet doesn't allow me to post all the code.)

  • Red color picker uses horizontal normal
  • Blue uses vertical normal.
  • Green uses horizontal flipped.
  • Aqua uses vertical flipped.

Haven't tested in IE.

http://jsfiddle.net/4z7d6ze5/2/

Called like this:

$(document).ready(function() {
    $("#custom").spectrum({
        color: "#FF0000",
        showAlpha: true
    });
    $("#custom2").spectrum({
        color: "#0000FF",
        showAlpha: true,
        alphaVertical: true
    });
    $("#custom3").spectrum({
        color: "#00FF00",
        showAlpha: true,
        flipAlpha: true
    });
    $("#custom4").spectrum({
        color: "#00FFFF",
        showAlpha: true,
        flipAlpha: true,
        alphaVertical: true
    });
});
teynon
  • 7,540
  • 10
  • 63
  • 106
  • Exactly what I was looking for! Did you change the css? – Horay Dec 15 '15 at 03:16
  • You should deffinetely add this to the pull request on github: https://github.com/bgrins/spectrum/pulls I was working the whole day on this, and now finally I get the solution! – Horay Dec 15 '15 at 03:20
  • 1
    @Horay https://github.com/bgrins/spectrum/pull/384 I'm not too sure I see a major benefit to these changes, but perhaps they will accept them. – teynon Dec 15 '15 at 04:53