What I can suggest is to use input range oninput event to follow the value of the input and use a proportional margin-left with this value.
Here's the code you need:
$('input[type="range"]').on('input', function() {
$('span#a').css('margin-left', parseInt($(this).val() - 10) > 0 ? parseInt($(this).val() - 10) + '%' : '0px');
});
Demo:
$('input[type="range"]').on('input', function() {
$('span#a').css('margin-left', parseInt($(this).val() - 10) > 0 ? parseInt($(this).val() - 10) + '%' : '0px');
});
input {
width: 90%;
}
span#a {
display: block;
width: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="range" min="0" max="100" step="1" value="0" />
<span id="a">I'm following.</span>
Note:
This will update the
spanleft margin to be proportional to value of therange, so it will be updating between0%to100%, which gives it the floating effect.In the following sample Demo, the
margin-leftvalue needs more
adjusting so it will give a better result. The logic is there, but
needs just some adjustment.
I'm ultimately trying to scrape all of the top movie databases (starting with IMDB,) to generate a list of top IMDB movies that are organised by rating, genre, etc.
I'm just learning functions and I'm a little stuck. My code works, but I can't figure out how to easily limit the input range of the rating (IMDB rating is capped at 10.0, therefore it needs to call an error if past that) - this should sort itself out when I automate the values but for now it's a manual process and I just wanna learn how to do it for the sake of learning. My code thus far:
def movie_review(rating):
if rating < 6.9:
return "Avoid"
elif rating < 8:
return "Pretty decent"
else:
return "Outstanding movie"
def movie_name(x):
return x, rating
x = input("Enter movie name: ")
rating = float(input("Enter rating: "))
a = movie_review(rating)
b = movie_name(x)
print(b)
print(a)Thank you!(!!!!!)
Edit: just noting, the variables that define how good a movie is will change. I know there are some good movies with a lower than 7 rating, I'm not a ratings snob; it's all temporary for now. 😅
Edit#2: I love you guys, thanks everyone.
html - Is there a float input type in HTML5? - Stack Overflow
html - Step parameter for input type of range - Stack Overflow
python - range() for floats - Stack Overflow
Custom Number Input with limited range - Max and Min float value - Get Help - Adalo
What I can suggest is to use input range oninput event to follow the value of the input and use a proportional margin-left with this value.
Here's the code you need:
$('input[type="range"]').on('input', function() {
$('span#a').css('margin-left', parseInt($(this).val() - 10) > 0 ? parseInt($(this).val() - 10) + '%' : '0px');
});
Demo:
$('input[type="range"]').on('input', function() {
$('span#a').css('margin-left', parseInt($(this).val() - 10) > 0 ? parseInt($(this).val() - 10) + '%' : '0px');
});
input {
width: 90%;
}
span#a {
display: block;
width: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="range" min="0" max="100" step="1" value="0" />
<span id="a">I'm following.</span>
Note:
This will update the
spanleft margin to be proportional to value of therange, so it will be updating between0%to100%, which gives it the floating effect.In the following sample Demo, the
margin-leftvalue needs more
adjusting so it will give a better result. The logic is there, but
needs just some adjustment.
https://jsfiddle.net/2cc83shx/2/
$( document ).ready( function() {
$( '#rangeInput' ).on( 'change', function() {
$( '#a' ).css({
'transform': 'translateX(' + $(this).val() + 'px)'
})
})
})
I can help a bit. you can positioning it a bit better later from my fiddle. (here, I'm using jquery to select the element. you can use pure js to do this too)
*UPDATE
If you want it to follow whenever you drag the range, follow the code below
https://jsfiddle.net/2cc83shx/3/
The number type has a step value controlling which numbers are valid (along with max and min), which defaults to 1. This value is also used by implementations for the stepper buttons (i.e. pressing up increases by step).
Simply change this value to whatever is appropriate. For money, two decimal places are probably expected:
<label for="totalAmt">Total Amount</label>
<input type="number" step="0.01" id="totalAmt">
(I'd also set min=0 if it can only be positive)
If you'd prefer to allow any number of decimal places, you can use step="any" (though for currencies, I'd recommend sticking to 0.01). In Chrome & Firefox, the stepper buttons will increment / decrement by 1 when using any. (thanks to Michal Stefanow's answer for pointing out any, and see the relevant spec here)
Here's a playground showing how various steps affect various input types:
<form>
<input type=number step=1 /> Step 1 (default)<br />
<input type=number step=0.01 /> Step 0.01<br />
<input type=number step=any /> Step any<br />
<input type=range step=20 /> Step 20<br />
<input type=datetime-local step=60 /> Step 60 (default)<br />
<input type=datetime-local step=1 /> Step 1<br />
<input type=datetime-local step=any /> Step any<br />
<input type=datetime-local step=0.001 /> Step 0.001<br />
<input type=datetime-local step=3600 /> Step 3600 (1 hour)<br />
<input type=datetime-local step=86400 /> Step 86400 (1 day)<br />
<input type=datetime-local step=70 /> Step 70 (1 min, 10 sec)<br />
</form>
Run code snippetEdit code snippet Hide Results Copy to answer Expand
As usual, I'll add a quick note: remember that client-side validation is just a convenience to the user. You must also validate on the server-side!
Via: http://blog.isotoma.com/2012/03/html5-input-typenumber-and-decimalsfloats-in-chrome/
But what if you want all the numbers to be valid, integers and decimals alike? In this case, set step to “any”
<input type="number" step="any" />
Works for me in Chrome, not tested in other browsers.
http://jsfiddle.net/Df57B/
Check out this demo it is possible to give steps in decimal.
<input type="range" name="points" min="1" max="10"
step="0.25" onchange="alert(this.value)"/>
Your mistake take is that you gave .25 instead of 0.25.
The following works for me in chrome, I'm thinking that it's the shortcut step=".25" that won't work
<input id="something" type="range" min="0" max="0" step ="0.25" value="5" />
You can either use:
[x / 10.0 for x in range(5, 50, 15)]
or use lambda / map:
map(lambda x: x/10.0, range(5, 50, 15))
I used to use numpy.arange but had some complications controlling the number of elements it returns, due to floating point errors. So now I use linspace, e.g.:
>>> import numpy
>>> numpy.linspace(0, 10, num=4)
array([ 0. , 3.33333333, 6.66666667, 10. ])
Keep "min" to be the minimalistic value that you might need. Keep "step" to such a value which covers all the values.
For example: (if the lowest value you take is 0.005)
<input type="number" [formControl]="pQuantity" class="form-control" id="qt" placeholder="Enter quantity"
name="pqt" min="0.005" step="0.001" required>
You can use the onkeyup attribute
<input type="number" onkeyup="if(this.value<=0){this.value = 1}">
Or you could simply set the min value to something like this 0.0000001
<input type="number" min=0.0000001>
If you're not supporting old browsers, you can take advantage of the
<input type="range">
and some JavaScript to follow it along. See my Codepen: http://codepen.io/abhisharma2/pen/wMOpqz
An example with custom output
It's updating while you drag the input.
var el, newPoint, newPlace, offset;
$('input[type=range]').on('input', function () {
$(this).trigger('change');
});
// Select all range inputs, watch for change
$("input[type='range']").change(function() {
// Cache this for efficiency
el = $(this);
// Measure width of range input
width = el.width();
// Figure out placement percentage between left and right of input
newPoint = (el.val() - el.attr("min")) / (el.attr("max") - el.attr("min"));
offset = -1;
// Prevent bubble from going beyond left or right (unsupported browsers)
if (newPoint < 0) { newPlace = 0; }
else if (newPoint > 1) { newPlace = width; }
else { newPlace = width * newPoint + offset; offset -= newPoint; }
// Move bubble
el
.next("output")
.css({
left: newPlace,
marginLeft: offset + "%"
})
.text(el.val());
})
// Fake a change to position bubble at page load
.trigger('change');
output {
position: absolute;
background-image: linear-gradient(#444444, #999999);
width: 40px;
height: 30px;
text-align: center;
color: white;
border-radius: 10px;
display: inline-block;
font: bold 15px/30px Georgia;
bottom: 175%;
left: 0;
margin-left: -1%;
}
output:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 10px solid #999999;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
top: 100%;
left: 50%;
margin-left: -5px;
margin-top: -1px;
}
form {
position: relative;
margin: 50px;
}
body {
padding: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<form>
<input type="range" name="foo" min="0" max="100">
<output for="foo" onforminput="value = foo.valueAsNumber;"></output>
</form>
<form>
<input type="range" name="foo" min="0" max="100" style="width: 300px;">
<output for="foo" onforminput="value = foo.valueAsNumber;"></output>
</form>
<form>
<input type="range" name="foo" min="0" max="100">
<output for="foo" onforminput="value = foo.valueAsNumber;"></output>
</form>
reference https://css-tricks.com/value-bubbles-for-range-inputs/