Anybody know of a way to prevent the page jumping to an input when is is changed? Particularly if it's changed with a label button from elsewhere on the page.
This problem affects IE, Chrome Canary, FireFox, and probably some others, in-fact the only browser it doesn't seem to affect is Chrome v28.
You can see the problem here: http://jsfiddle.net/FgaWM/3/
Normally this would be a useful feature, but in my case it is quite annoying, I need a way to prevent it / override it.
I've tried forcing the scroll position with JQuery:
var labelPos = $(window).scrollTop();
$(window).scrollTop(labelPos);
This solution is... buggy at best, causing momentary page flicker.
Anyone have a better way?
Edit: I figured-out a solution :P
$('label').click(function(e) {
e.preventDefault();
var For = $(this).attr('for');
$('#' + For).trigger('click');
});
To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.
Place a panel in location where you want the label to be, set it's AutoScroll property to true. Then place the label in the panel, anchor it and set it's AutoSize property to true. This will make the panel provide the scroll bars if the label's text extends outside of the panel.
$('label[for]').on('click', function (e) {
var target = window[this.htmlFor];
target.checked = !target.checked;
e.preventDefault();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With