Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when resize viewport, width & formatting value #353

Open
miraahmad opened this issue Jan 19, 2018 · 1 comment
Open

Problem when resize viewport, width & formatting value #353

miraahmad opened this issue Jan 19, 2018 · 1 comment

Comments

@miraahmad
Copy link

miraahmad commented Jan 19, 2018

I want to set the input value as timer & I managed to achieve that by using 'format'

`$('#knob1').knob({

'min': 0,
'max': 60,
'step': 1, 
// 'width': 200,     
'thickness': 0.3,
'fgColor': '#06BABC',
'bgColor': '#333',	
'format' : function(v) {			
 	var sec = parseInt(v)*60;
	var min = Math.floor(sec / 60);
	sec -= min * 60;
	return min + ':' + (sec < 10 ? "0" + sec : sec);
}});`

image

I tried to make it responsive by setting the data-width to 80% but when I resized the viewport the value changed to normal number (eg: 25:00 -> 25)

image

if I add fixed width to the knob -> 'width': 200, the value displayed as what I want but it's not responsive & turned out like this

image

I also try using $(window).resize(function() {}); to get the width of the knob when resizing & dynamically change the value into 'width' but it's still not working.

Any advice?

https://jsfiddle.net/bf8aLtwj/

@samudiogo
Copy link

Hi! I updated your jsfiddle https://jsfiddle.net/bf8aLtwj/18/ with this approach:

  • separate the main format function from optons:
    var format = function(v) { var sec = parseInt(v)*60; var min = Math.floor(sec / 60); sec -= min * 60; return min + ':' + (sec < 10 ? "0" + sec : sec); };

  • then I call at draw event instead of format hook:
    `
    $('#knob1').knob({
    'min': 0,
    'max': 60,
    'width': '100%',
    'step': 1,
    'thickness': 0.3,
    'fgColor': '#06BABC',
    'bgColor': 'Disable Knob redraw on screen Resize #333',
    'draw': function(){
    this.i.val(format(this.cv));
    }
    });

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants