You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,6 +49,7 @@ $('.color').colorPicker({
49
49
renderCallback:function($elm, toggled) {}, // this === instance; $elm: the input field;toggle === true -> just appeared; false -> opposite; else -> is rendering on pointer move
50
50
// toggled true/false can for example be used to check if the $elm has a certain className and then hide alpha,...
51
51
buildCallback:function($elm) {}, // this === instance; $elm: the UI
52
+
positionCallback:function($elm) {return {top: y, left: x}}, // this === instance; $elm: the trigger element;
52
53
css:'', // replaces existing css
53
54
cssAddon:'', // adds css to existing
54
55
margin:'', // positioning margin (can also be set in cssAddon)
@@ -63,6 +64,26 @@ $('.color').colorPicker({
63
64
```
64
65
#### Some tips
65
66
67
+
The positionCallback can be used to optionally position the colorPicker different from its default; in case you want it to also show above or to the left of the input field etc.
68
+
The callback will also be called on scroll.
69
+
You need to return an object that holds ```left``` and ```top``` to position the colorPicker. See ./demo/index.js for an example:
70
+
71
+
```javascript
72
+
positionCallback:function($elm) {
73
+
var_$UI=this.$UI, // this is the instance; this.$UI is the colorPicker DOMElement
74
+
position =$elm.offset(), // $elm is the current trigger that opened the UI
75
+
gap =this.color.options.gap, // this.color.options stores all options
76
+
top =0,
77
+
left =0;
78
+
79
+
// do here your calculations with top and left and...
80
+
return { // the object will be used as in $('.something').css({...});
81
+
left: left,
82
+
top: top
83
+
}
84
+
}
85
+
```
86
+
66
87
The renderCallback can be used as openCallback and closeCallback:
0 commit comments