简体   繁体   English

向jQuery旋钮滑块添加按钮

[英]Add a button to jQuery-Knob slider

I need your help. 我需要你的帮助。 I'm working on the project where necessary to implement a circular slider with draggable button-control by it. 我正在进行必要的项目,以实现带有可拖动按钮控制的圆形滑块。 I decided to use this jQuery-Knob slider . 我决定使用此jQuery-Knob滑块 it's great but I need to add button that could be possible to set styles and be dragged 很棒,但是我需要添加可以设置样式并拖动的按钮

I made a decision to add div element through javascript and then tie native Jquery Knob params of dragging to it. 我决定通过JavaScript添加div元素,然后将其拖到本地Jquery Knob参数中。

Here what I have done 我在这里做了

在此处输入图片说明

And here is my code 这是我的代码

function addBtnControl(self) {
              // cache variables
              var button = document.getElementById('knob-ctrl'),
                  cx = 22*self.scale,
                  cy = 20*self.scale,
                  a = self.arc(self.cv),
                  start = xyOnArc(self.xy-cx, self.xy-cy, self.radius/self.scale, a.s);

              // check if pointer-events are supported
              // if not than use fallback btn ctrl for IE
              App.config.Modernizr.addTest('csspointerevents',function(){
                return 'pointerEvents' in document.documentElement.style;
              });
              if (App.config.Modernizr.csspointerevents) {
                self.cursorExt = 0;

                button.style.left = start.x + "px";
                button.style.top = start.y + "px";
              }

              function xyOnArc(cx, cy, radius, radianAngleX) {
                var x = cx + radius * Math.cos(radianAngleX);
                var y = cy + radius * Math.sin(radianAngleX);
                return ({
                    x: x,
                    y: y
                });
              }
            }

            // init Button Ctrl

            addBtnControl(this); 

I dynamically added a button and borrowed params that must be enough to make a well-suited draggable control but I've been doing something wrong because if I scale a browser or just open on another screen size it looks like this 我动态添加了一个按钮,并借用了足以构成合适的可拖动控件的参数,但是我做错了,因为如果缩放浏览器或只是在另一个屏幕上打开,它看起来像这样

So something wrong with the functions and params that passed to it. 所以传递给它的函数和参数有问题。

在此处输入图片说明

Actually jQuery knob was using Canvas, so adding external layers with it makes more complex. 实际上jQuery旋钮使用的是Canvas,因此添加外部图层会使其更加复杂。

Alternatively i suggest to use the jQuery roundSlider plugin which is similar to knob, but it constructs based on the div elements only. 另外,我建议使用类似于旋钮的jQuery roundSlider插件,但它仅基于div元素进行构造。 So you can make any custom appearances as per your wish. 因此,您可以根据需要进行任何自定义外观。

For more details check the demos and documentation page. 有关更多详细信息,请查看演示文档页面。

Check this demo from jsFiddle which is similar to your requirement. jsFiddle检查此演示,这与您的要求类似。

Screenshot of the Output: 输出的屏幕截图:

jQuery圆形滑块-自定义外观

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM