![](/img/trans.png)
[英]How can I rotate an element to 180deg the back to 0deg using the same button in javascript
[英]How to Rotate 180 Deg
我實現了光譜顏色選擇器 。 我正在嘗試將.alphaSlider
旋轉180度。 當然,我可以使用CSS來做到這一點(使用transform: rotate(180deg)
),但這有點像hack,而且總會有其他問題。 我想用JavaScript源文件來做。
如何編輯源文件,以便可以旋轉180度.alphaSlider
?
以下是相關代碼:
draggable(alphaSlider, function (dragX, dragY, e) {
currentAlpha = (dragX / alphaWidth);
isEmpty = false;
if (e.shiftKey) {
currentAlpha = Math.round(currentAlpha * 10) / 10;
}
move();
}, dragStart, dragStop);
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));
繁榮! 做完了 參見jsfiddle。 (摘錄不允許我發布所有代碼。)
尚未在IE中進行測試。
http://jsfiddle.net/4z7d6ze5/2/
這樣稱呼:
$(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
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.