HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<h1>jquery-rsSliderLens demonstration</h1>
<p>With this plug-in, you can change the default input range, from this:</p>
<pre>
<input type="range">
</pre>
<section>
<!-- 0 -->
<input type="range">
<label></label>
</section>
<p>to:</p>
<pre>
<input type="range">
<script>
<span>$("input").rsSliderLens();</span>
</script>
</pre>
<section>
<!-- 1 -->
<input type="range">
<label></label>
</section>
<p>To use a step 25, you can add a <code>step</code> attribute to the <code><input></code> element or add a parameter to the plug-in constructor:</p>
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
<span>step: 25</span>
});
</script>
</pre>
<section>
<!-- 2 -->
<input type="range">
<label></label>
</section>
<p>The 0 and 100 labels are cropped! No problem, just add a padding space equal to 10% of the slider width:</p>
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
step: 25,
<span>paddingStart: 0.1,
paddingEnd: 0.1</span>
});
</script>
</pre>
<section>
<!-- 3 -->
<input type="range">
<label></label>
</section>
<p>By default <code><input type="range"></code> has a range between 0 and 100.<br>
For other ranges, you can add <code>min</code> and <code>max</code> attributes to the <code><input></code> element, or in the plug-in constructor:</p>
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
step: 25,
paddingStart: 0.1,
paddingEnd: 0.1,
<span>min: -50,
max: 150</span>
});
</script>
</pre>
<section>
<!-- 4 -->
<input type="range">
<label></label>
</section>
<p>Great, but now the labels overlap each other.<br>
To fix this, you have some options: (click each one for a sample)</p>
<aside class="opt1">
<label><input name="opt" type="radio" value="1" checked>Increase the slider width in CSS;</label>
<label><input name="opt" type="radio" value="2">Increase the slider width in the plug-in constructor;</label>
<label><input name="opt" type="radio" value="3">Use a vertical slider;</label>
<label><input name="opt" type="radio" value="4">Hide the labels;</label>
<label><input name="opt" type="radio" value="5">Use a fixed handle slider.</label>
</aside>
<div id="o1">
<pre>
<input type="range">
<span><style>
input {
width: 400px;
}
</style></span>
<script>
$("input").rsSliderLens({
step: 25,
paddingStart: 0.1,
paddingEnd: 0.1,
min: -50,
max: 150
});
</script>
</pre>
<section>
<!-- 5 -->
<input type="range">
<label></label>
</section>
</div>
<div id="o2">
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
<span>width: 400,</span>
step: 25,
paddingStart: 0.1,
paddingEnd: 0.1,
min: -50,
max: 150
});
</script>
</pre>
<section>
<!-- 6 -->
<input type="range">
<label></label>
</section>
</div>
<div id="o3">
<pre>
<input type="range">
<span><style>
input {
width: 40px;
height: 300px;
}
</style></span>
<script>
$("input").rsSliderLens({
step: 25,
paddingStart: 0.1,
paddingEnd: 0.1,
min: -50,
max: 150
});
</script>
</pre>
<section>
<!-- 7 -->
<input type="range">
<label></label>
</section>
</div>
<div id="o4">
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
step: 25,
min: -50,
max: 150,
<span>ruler: {
labels: {
visible: false
}
}</span>
});
</script>
</pre>
<section>
<!-- 8 -->
<input type="range">
<label></label>
</section>
</div>
<div id="o5">
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
step: 25,
paddingStart: 0.1,
paddingEnd: 0.1,
min: -50,
max: 150,
<span>fixedHandle: true,
ruler: {
size: 4 <mark>// 400% of the <input type=range> width</mark>
}</span>
});
</script>
</pre>
<section>
<!-- 9 -->
<input type="range">
<label></label>
</section>
</div>
<p>Use a range to restrict input even further:</p>
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
width: 300,
height: 45,
step: 10,
paddingStart: 0.1,
paddingEnd: 0.1,
<span>range: {
type: [20, 60],
draggable: true
}</span>
});
</script>
</pre>
<section>
<!-- 10 -->
<input type="range">
<label></label>
</section>
<p class="small">Use your mouse to drag the range to other location</p>
<p>If you want labels every 20 positions, but with a <code>step</code> of 1:</p>
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
<span>step: 1,</span>
paddingStart: 0.1,
paddingEnd: 0.1,
<span>ruler: {
labels: {
values: [0, 20, 40, 60, 80, 100]
}
}</span>
});
</script>
</pre>
<section>
<!-- 11 -->
<input type="range">
<label></label>
</section>
<p>The same slider, but now with a fixed handle style with a <code>min</code> of 0 and <code>max</code> of 500:</p>
<pre>
<input type="range">
<script>
<span>var labels = [];
for (var i = 0; i <= 500; i+= 20) {
labels.push(i);
}</span>
$("input").rsSliderLens({
<span>step: 1,</span>
paddingStart: 0.1,
paddingEnd: 0.1,
<span>width: 300,
max: 500,
fixedHandle: true,
ruler: {
labels: {
values: labels
}
}</span>
});
</script>
</pre>
<section>
<!-- 12 -->
<input type="range">
<label></label>
</section>
<p>Using customized events to display current value inside the handle and to style labels:</p>
<pre>
<input type="range">
<span><style>
#custom + .range, <mark>// range outside the handle </mark>
#custom ~ .handle .range { <mark>// range inside the handle </mark>
background: -moz-linear-gradient(left, red 0%, green 100%);
background: -webkit-linear-gradient(left, red 0%, green 100%);
background: linear-gradient(to right, red 0%, green 100%);
}
</style></span>
<script>
$("input").rsSliderLens({
step: 1,
paddingStart: 0.1,
paddingEnd: 0.1,
min: -20,
max: 20,
ruler: {
labels: {
values: [-20, -10, 0, 10, 20],
<span>onCustomLabel: function(event, value) {
return value > 0 ? '+' + value : value;
},
onCustomAttrs: function(event, value) {
if (value < 0) return { style: 'fill:red' };
if (value > 0) return { style: 'fill:green' };
<mark>// no style defined for zero, so returns nothing (or undefined)</mark>
}</span>
}
},
<span>onCreate: function (event) {
<mark>// append a new child <label> element to the .handle</mark>
$(event.currentTarget).nextAll(".handle").append("<label>");
},
onChange: function (event, value) {
<mark>// use the <label> element created at run-time, to display the current value</mark>
var $labelElement = $(event.currentTarget).nextAll(".handle").children("label");
$labelElement.text(value < 0 ? value : ((value > 0 ? '+' : '') + value));
}</span>
});
</script>
</pre>
<section>
<!-- 13 -->
<input type="range" id="custom">
</section>
<p>You have the choice of <code>OnChange</code> or <code>OnFinalChange</code> (recommended for computationally expensive tasks)</p>
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
<span>onChange: function (event, value) {
$changeLabel.text(value);
},
onFinalChange: function (event, value) {
$finalChangeLabel.text(value);
}</span>
});
</script>
</pre>
<section>
<!-- 14 -->
<input type="range">
<aside id="changeLabels">
<label></label>
<label></label>
</aside>
</section>
<p>Did I mention the support for double handle sliders?</p>
<pre>
<input type="range">
<script>
$("input").rsSliderLens({
<span>value: [10, 25]</span>
});
</script>
</pre>
<section>
<!-- 15 -->
<input type="range">
<aside id="doubleHandleLabels">
<label></label>
<label></label>
</aside>
</section>
<p>You can bind the plug-in to any element, not only to an <code><input type=range></code>:</p>
<pre>
<span>Hello world</span>
<script>
$("span").rsSliderLens({ ruler: { visible: false } });
</script>
</pre>
<section class="bottommargin">
<!-- 16 -->
<span class="slider">Hello world</span>
<label></label>
</section><br>
<pre>
<span>
<img src="./pic1.jpg" width="60" height="40">
<img src="./pic2.jpg" width="60" height="40">
<img src="./pic3.jpg" width="60" height="40">
</span>
<script>
$("span").rsSliderLens({ ruler: { visible: false } });
</script>
</pre>
<section>
<!-- 17 -->
<span class="slider">
<img src="//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/pic1.jpg" width="60" height="40">
<img src="//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/pic2.jpg" width="60" height="40">
<img src="//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/pic3.jpg" width="60" height="40">
</span>
<label></label>
</section>
<p class="small"><br>Or with a little more customization</p>
<pre>
<span tabindex="0">
<img src="./pic1.jpg" width="60" height="40">
<img src="./pic2.jpg" width="60" height="40">
<img src="./pic3.jpg" width="60" height="40">
</span>
<script>
$("span").rsSliderLens({
<span>max: 2,
step: 1,
paddingStart: .15,
paddingEnd: .15,</span>
ruler: { visible: false }
});
</script>
</pre>
<section class="bottommargin">
<!-- 18 -->
<span class="slider" tabindex="0">
<img src="//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/pic1.jpg" width="60" height="40">
<img src="//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/pic2.jpg" width="60" height="40">
<img src="//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/pic3.jpg" width="60" height="40">
</span>
<label class="imgs"></label>
</section>
<p class="small">The tabindex makes the slider keyboard focusable</p>
<p>Responsive design. Please, resize your browser window.</p>
<p class="small">This is possible with the use of relative CSS units.<br>Don't like the dark layout? You can recompile LESS files to generate the layout you like.</p><br>
<pre>
<input type="range">
<script>
$("span").rsSliderLens();
</script>
</pre>
<section class="resize">
<!-- 19 -->
<input class="horiz" type="range"><br>
<!-- 20 -->
<input class="horiz" type="range"><br>
<!-- 21 -->
<input class="vert" type="range">
<!-- 22 -->
<input class="vert" type="range">
</section>
<p>You have total flexibility over the style.</p>
<p class="small cssfun">Just change the CSS (not the javascript) to give wings to your imagination.</p>
<section id="cssfun1">
<label></label>
<!-- 23 -->
<span class="slider" tabindex="0"></span>
</section>
<section id="cssfun2">
<label></label>
<!-- 24 -->
<input type="range">
<label></label>
</section>
<section id="cssfun3">
<!-- 25 -->
<span class="slider" tabindex="0"> <!-- tabindex to enable keyboard focus -->
<ul>
<li>
iPhone<br>SE</li><li>
iPhone<br>7</li><li>
LG<br>G5</li><li>
Samsung<br>S7</li><li>
OnePlus<br>3</li><li>
HTC<br>10</li><li>
Huawei<br>P9</li>
</ul>
</span>
<figure class="phone0"></figure>
</section>
<section id="cssfun4">
<!-- 26 -->
<input type="range">
</section>
<section id="cssfun5">
<!-- 27 -->
<span class="slider" tabindex="0">
January<br>
February<br>
March<br>
April<br>
May<br>
June<br>
July<br>
August<br>
September<br>
October<br>
November<br>
December
</span>
</section>
<a class="github" href="https://github.com/ruisoftware/jquery-rsSliderLens" target="github">More on GitHub</a>
@background: #454545;
@deltaContrast: 20%;
@text: fadeout(#fff - @background, 40%);
@tickmarks: @text;
// scalar values
// ===============
@refScale: 1em; // Allowed units are: px, pt (for fixed layout) or em, rem, vw, vh, vmin, vmax (for elastic layout).
// To try other sizes, you only need to change this line. All the rest will resize according to this @refScale
// 1em corresponds to 16px in most browsers, which is the default font size.
// However, some users might define another default font size for accessibility reasons.
// To convert px to em, do em = px/16. Example: 8px = .5em
@fromGradientOuter: darken(@background, @deltaContrast);
@toGradientOuter: lighten(@background, @deltaContrast);
@fromGradientInner: darken(@toGradientOuter, 10%);
@toGradientInner: darken(@fromGradientOuter, 2%);
@borderColor: darken(@fromGradientOuter, lightness(@background)/5 + 3%);
@rangeWrapper: darken(@fromGradientOuter, 5%);
@range: lighten(@fromGradientOuter, 12%);
body {
background-color: @background;
}
.sliderlens {
opacity: .8;
&.focus {
opacity: 1;
}
cursor: pointer;
@zero: 0%;
@half: 50%;
@full: 100%;
@grad1: fade(darken(@fromGradientInner, 10%), 95%);
@grad2: fade(lighten(@fromGradientInner, 10%), 25%);
@grad3: fade(darken(@fromGradientInner, 15%), 25%);
@grad4: fade(darken(@fromGradientInner, 15%), 95%);
.range {
background-color: @rangeWrapper;
border-width: @refScale*0.0625;
border-style: solid;
.borderlineargradient2grads(top, @fromGradientOuter, @toGradientOuter, to bottom);
> div {
background-color: @range;
}
&.drag {
> div {
cursor: ew-resize;
}
&.dragging > div {
cursor: none;
}
}
}
> .handle,
> .handle1,
> .handle2 {
&:before,
&:after {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
border-radius: ~"3em/.75em";
cursor: ew-resize;
background-color: @background;
box-shadow: 0 0 @refScale*0.3125 -@refScale*0.03125 @borderColor;
border: 0 solid @toGradientOuter;
border-bottom-color: @fromGradientOuter;
border-width: @refScale*0.0625 0;
&.dragging {
box-shadow: 0 0 @refScale*0.3125 -@refScale*0.0625 @borderColor;
}
.range {
.borderlineargradient2grads(top, @fromGradientOuter, lighten(@toGradientOuter, 35%), to bottom);
}
}
> .handle {
&:before {
right: 50%;
bottom: 55%;
border-right: @refScale*0.0625 solid @text;
z-index: 1;
}
&:after {
.lineargradient(left, @grad1 @zero, @grad2 @half, @grad3 @half, @grad4 @full, to right);
}
}
> .handle1 {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
&:after {
.lineargradient(left, @grad1 @zero, @grad2 @full, to right);
}
}
> .handle2 {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
&:after {
.lineargradient(left, @grad3 @zero, @grad4 @full, to right);
}
}
svg {
> path {
stroke: @tickmarks;
}
> g > text {
fill: @text;
font-size: .5em;
}
}
&.vert {
> .handle,
> .handle1,
> .handle2 {
cursor: ns-resize;
border-radius: ~"3em/.75em";
.range {
.borderlineargradient2grads(top, @fromGradientOuter, @toGradientOuter, to bottom);
}
}
> .handle {
&:before {
right: 55%;
bottom: 50%;
border-right: none;
border-bottom: @refScale*0.0625 solid @text;
}
&:after {
.lineargradient(top, @grad1 @zero, @grad2 @half, @grad3 @half, @grad4 @full, to bottom);
}
}
> .handle1 {
border-bottom: none;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
&:after {
.lineargradient(top, @grad1 @zero, @grad2 @full, to bottom);
}
}
> .handle2 {
border-top: none;
border-top-left-radius: 0;
border-top-right-radius: 0;
&:after {
.lineargradient(top, @grad3 @zero, @grad4 @full, to bottom);
}
}
}
&.fixed {
border-width: @refScale*0.0625;
border-style: solid;
.borderlineargradient2grads(top, @fromGradientOuter, @toGradientOuter, to bottom);
background-color: darken(@background, 5%);
cursor: ew-resize;
&:before,
&:after {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border-width: 0 0 @refScale*0.0625 0;
border-style: solid;
pointer-events: none;
.borderlineargradient2grads(top, darken(@fromGradientOuter, 5%), darken(@toGradientOuter, 10%), to bottom);
}
&:after {
border-width: 0 @refScale*0.0625;
box-shadow:
inset @refScale 0 @refScale*1.25 -@refScale*.5 @borderColor,
inset -@refScale 0 @refScale*1.25 -@refScale*.5 @borderColor;
}
&.vert {
cursor: ns-resize;
&:before {
border-width: 0 @refScale*0.0625;
}
&:after {
border-width: 0 0 @refScale*0.0625 0;
box-shadow:
/*inset 0 0 @refScale*.25 @borderColor,*/
inset 0 @refScale @refScale*1.25 -@refScale*.5 @borderColor,
inset 0 -@refScale @refScale*1.25 -@refScale*.5 @borderColor;
}
}
> .handle {
border-radius: 0;
border: none;
}
}
&.vert {
.range {
&.drag > div {
cursor: ns-resize;
}
}
}
&.dragging {
cursor: none;
> .handle,
> .handle1,
> .handle2 {
cursor: none;
}
}
}
// mixins
// ===============
.padding(@padding) {
.padding(@padding, @padding, @padding, @padding);
}
.padding(@topBottom, @rightLeft) {
.padding(@topBottom, @rightLeft, @topBottom, @rightLeft);
}
.padding(@top, @right, @bottom) {
.padding(@top, @right, @bottom, @right);
}
.padding(@top, @right, @bottom, @left) when(@top = @right) and (@right = @bottom) and (@bottom = @left) {
padding: @top;
}
.padding(@top, @right, @bottom, @left) when (@top = @bottom) and (@right = @left) and not (@top = @right) {
padding: @top @right;
}
.padding(@top, @right, @bottom, @left) when not (@top = @bottom), not (@right = @left) {
padding: @top @right @bottom @left;
}
.margin(@margin) {
.margin(@margin, @margin, @margin, @margin);
}
.margin(@topBottom, @rightLeft) {
.margin(@topBottom, @rightLeft, @topBottom, @rightLeft);
}
.margin(@top, @right, @bottom) {
.margin(@top, @right, @bottom, @right);
}
.margin(@top, @right, @bottom, @left) when (@top = @right) and (@right = @bottom) and (@bottom = @left) {
margin: @top;
}
.margin(@top, @right, @bottom, @left) when (@top = @bottom) and (@right = @left) and not (@top = @right) {
margin: @top @right;
}
.margin(@top, @right, @bottom, @left) when not (@top = @bottom), not (@right = @left) {
margin: @top @right @bottom @left;
}
.lineargradient(@dir, @g1, @g2, @w3cDir) {
background: -webkit-linear-gradient(@dir, @g1, @g2);
background: -moz-linear-gradient(@dir, @g1, @g2);
background: -o-linear-gradient(@dir, @g1, @g2);
background: -ms-linear-gradient(@dir, @g1, @g2);
background: linear-gradient(@w3cDir, @g1, @g2);
}
.lineargradient(@dir, @g1, @g2, @g3, @w3cDir) {
background: -webkit-linear-gradient(@dir, @g1, @g2, @g3);
background: -moz-linear-gradient(@dir, @g1, @g2, @g3);
background: -o-linear-gradient(@dir, @g1, @g2, @g3);
background: -ms-linear-gradient(@dir, @g1, @g2, @g3);
background: linear-gradient(@w3cDir, @g1, @g2, @g3);
}
.lineargradient(@dir, @g1, @g2, @g3, @g4, @w3cDir) {
background: -webkit-linear-gradient(@dir, @g1, @g2, @g3, @g4);
background: -moz-linear-gradient(@dir, @g1, @g2, @g3, @g4);
background: -o-linear-gradient(@dir, @g1, @g2, @g3, @g4);
background: -ms-linear-gradient(@dir, @g1, @g2, @g3, @g4);
background: linear-gradient(@w3cDir, @g1, @g2, @g3, @g4);
}
.lineargradient2grads(@g1, @g2, @w3cG1, @w3cG2) {
background: -webkit-linear-gradient(@g1), -webkit-linear-gradient(@g2);
background: -moz-linear-gradient(@g1), -moz-linear-gradient(@g2);
background: -o-linear-gradient(@g1), -o-linear-gradient(@g2);
background: -ms-linear-gradient(@g1), -ms-linear-gradient(@g2);
background: linear-gradient(@w3cG1), linear-gradient(@w3cG2);
}
.borderlineargradient2grads(@dir, @g1, @g2, @w3cDir) {
-webkit-border-image: -webkit-linear-gradient(@dir, @g1, @g2) 1;
-moz-border-image: -moz-linear-gradient(@dir, @g1, @g2) 1;
-o-border-image: -o-linear-gradient(@dir, @g1, @g2) 1;
-ms-border-image: -ms-linear-gradient(@dir, @g1, @g2) 1;
border-image: linear-gradient(@w3cDir, @g1, @g2) 1;
}
.user-select(@s) {
-o-user-select: @s;
-moz-user-select: @s;
-webkit-user-select: @s;
user-select: @s;
}
section {
margin: 1em 3em;
}
p {
margin-top: 3em;
color: #eee;
}
a.github {
display: block;
margin-top: 2em;
color: white;
}
$("#cssfun1 .slider").html(function() {
var str = "";
for(var speed = 0; speed <= 200; speed += 5) {
str += speed + "<br>";
}
return str;
});
var $inputs = $("input[type=range], span.slider"),
change = function (event, value, isFirstHandle) {
$(event.currentTarget).parent("div").next("label").text(value);
};
$inputs.eq(0).change(function () {
$(this).next("label").text(this.value);
}).change();
$inputs.eq(1).rsSliderLens({ onChange: change });
$inputs.eq(2).rsSliderLens({ step: 25, onChange: change });
$inputs.eq(3).rsSliderLens({ step: 25, paddingStart: 0.1, paddingEnd: 0.1, onChange: change });
$inputs.eq(4).rsSliderLens({ step: 25, paddingStart: 0.1, paddingEnd: 0.1, min: -50, max: 150, onChange: change });
$inputs.eq(5).rsSliderLens({ step: 25, paddingStart: 0.1, paddingEnd: 0.1, min: -50, max: 150, onChange: change });
$inputs.eq(6).rsSliderLens({ width: 400, step: 25, paddingStart: 0.1, paddingEnd: 0.1, min: -50, max: 150, onChange: change });
$inputs.eq(7).rsSliderLens({ step: 25, paddingStart: 0.1, paddingEnd: 0.1, min: -50, max: 150, onChange: change });
$inputs.eq(8).rsSliderLens({ step: 25, min: -50, max: 150, ruler: { labels: { visible: false }}, onChange: change });
$inputs.eq(9).rsSliderLens({ step: 25, paddingStart: 0.1, paddingEnd: 0.1, min: -50, max: 150, fixedHandle: true,
ruler: { size: 4 }, onChange: change
});
$inputs.eq(10).rsSliderLens({ width: 300, height: 45, step: 10, paddingStart: 0.1, paddingEnd: 0.1, range: { type: [20, 60], draggable: true }, onChange: change });
$inputs.eq(11).rsSliderLens({ step: 1, paddingStart: 0.1, paddingEnd: 0.1, ruler: { labels: { values: [0, 20, 40, 60, 80, 100] }}, onChange: change });
var labels = [];
for (var i = 0; i <= 500; i+= 20) {
labels.push(i);
}
$inputs.eq(12).rsSliderLens({ step: 1, paddingStart: 0.1, paddingEnd: 0.1, width: 300, max: 500, fixedHandle: true, ruler: { labels: { values: labels }, size: 4 }, onChange: change });
$inputs.eq(13).rsSliderLens({ step: 1, paddingStart: 0.1, paddingEnd: 0.1, min: -20, max: 20,
ruler: {
labels: {
values: [-20, -10, 0, 10, 20],
onCustomLabel: function(event, value) {
return value > 0 ? '+' + value : value;
},
onCustomAttrs: function(event, value) {
if (value < 0) return { style: 'fill:red' };
if (value > 0) return { style: 'fill:green' };
// no style defined for zero, so returns nothing (or undefined)
}
}
},
onCreate: function (event) {
// append a new child <label> element to the .handle
$(event.currentTarget).nextAll(".handle").append("<label>");
},
onChange: function (event, value) {
// use the <label> element created at run-time, to display the current value
var $labelElement = $(event.currentTarget).nextAll(".handle").children("label");
$labelElement.text(value < 0 ? value : ((value > 0 ? '+' : '') + value));
}
});
$inputs.eq(14).rsSliderLens({
onChange: function (event, value) {
$("#changeLabels label").first().text(value);
},
onFinalChange: function (event, value) {
$("#changeLabels label").last().text(value);
}
});
$inputs.eq(15).rsSliderLens({
step: 5,
width: 300,
paddingStart: .1,
paddingEnd: .1,
value: [10, 25],
onChange: function (event, value, isFirstHandle) {
$("#doubleHandleLabels label").eq(isFirstHandle ? 0 : 1).text(value);
}
});
$inputs.slice(16, 18).rsSliderLens({ ruler: { visible: false }, onChange: change });
$inputs.eq(18).rsSliderLens({ max: 2, step: 1, paddingStart: .15, paddingEnd: .15, ruler: { visible: false }, onChange: change });
$inputs.eq(19).rsSliderLens({ paddingStart: .1, paddingEnd: .1, ruler: { labels: { values: [0, 20, 40, 60, 80, 100] }} });
$inputs.eq(20).rsSliderLens({ paddingStart: .1, paddingEnd: .1, fixedHandle: true, ruler: { labels: { values: [0, 20, 40, 60, 80, 100] }} });
$inputs.eq(21).rsSliderLens({ width: 50, paddingStart: .1, paddingEnd: .1, orientation: 'vert', ruler: { labels: { values: [0, 20, 40, 60, 80, 100] }} });
$inputs.eq(22).rsSliderLens({ width: 50, paddingStart: .1, paddingEnd: .1, orientation: 'vert', fixedHandle: true, ruler: { labels: { values: [0, 20, 40, 60, 80, 100] }} });
$("aside input[type=radio]").change(function() {
$("aside").removeClass("opt1 opt2 opt3 opt4 opt5").addClass("opt" + this.value);
});
$("#o1, #o2, #o3, #o4, #o5").hide();
$inputs.eq(23).rsSliderLens({
min: 0,
max: 200,
height: 200,
fixedHandle: true,
step: 1,
paddingStart: .012,
paddingEnd: .012,
handle: {
zoom: 2
},
ruler: {
visible: false
},
onChange: function (event, value, isFirstHandle) {
$("#cssfun1 > label").text(value + " km/h");
}
});
$inputs.eq(24).rsSliderLens({
paddingStart: .075,
paddingEnd: .075,
value: [20, 40],
width: 300,
step: 1,
min: -20,
max: 70,
handle: {
size: .15
},
range: {
type: 'between'
},
ruler: {
labels: {
values: [-20, -10, 0, 10, 20, 30, 40, 50, 60, 70]
}
},
onChange: function (event, value, isFirstHandle) {
$("#cssfun2 > label").eq(isFirstHandle ? 0 : 1).text(value + "°C");
}
});
var animObj = {
$figure: $("#cssfun3 > figure")
};
$inputs.eq(25).rsSliderLens({
min: 0,
max: 6,
step: 1,
paddingStart: .07,
paddingEnd: .07,
ruler: {
visible: false
},
handle: {
zoom: 1.8,
animation: 300
},
onChange: function (event, value, isFirstHandle) {
if (animObj.timeoutIdHide) {
clearTimeout(animObj.timeoutIdHide);
}
animObj.timeoutIdHide = setTimeout(function () {
animObj.$figure.removeClass('phone0 phone1 phone2 phone3 phone4 phone5 phone6');
if (animObj.timeoutIdShow) {
clearTimeout(animObj.timeoutIdShow);
}
animObj.timeoutIdShow = setTimeout(function() {
animObj.$figure.addClass('phone' + value);
delete animObj.timeoutIdShow;
}, 100);
delete animObj.timeoutIdHide;
}, 200);
}
});
$inputs.eq(26).rsSliderLens({
height: 211,
min: 0,
max: 4,
step: 1,
flipped: true,
paddingStart: .2,
paddingEnd: .2,
handle: {
pos: .2,
zoom: 1
},
ruler: {
labels: {
pos: .4,
onCustomLabel: function (event, value) {
switch (value) {
case 0: return 'very unhappy';
case 1: return 'unhappy';
case 2: return 'normal';
case 3: return 'happy';
case 4: return 'very happy';
}
},
onCustomAttrs: function (event, value, x, y) {
return {
transform: 'rotate(-25 ' + x + ',' + y + ')',
'text-anchor': 'start'
};
}
},
tickMarks: {
short: { visible: false },
long: { visible: false }
},
onCustom: function(event, $svg, width, height, zoom, magnifiedRuler, createSvgDomFunc) {
if (magnifiedRuler) {
$svg.append(createSvgDomFunc('image', { width: 30, height: 155, x: 38, y: 27, 'href': '//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/emotions.png' }));
}
}
}
});
$inputs.eq(27).rsSliderLens({
min: 1,
max: 12,
height: 200,
fixedHandle: true,
step: 1,
paddingStart: .04,
paddingEnd: .04,
handle: {
size: .12
},
ruler: {
visible: false
}
});
var resizeObj = {
timeoutId: null,
doResize: function () {
$inputs.eq(19).add($inputs.eq(21)).rsSliderLens('resizeUpdate');
resizeObj.timeoutId = null;
},
resize: function () {
if (!resizeObj.timeoutId) {
resizeObj.timeoutId = setTimeout(resizeObj.doResize, 100);
}
}
};
resizeObj.doResize();
$(window).bind('resize', resizeObj.resize);
// to avoid image delays in the phone slider, load all of them at startup to the browser cache
$([
'//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/phone1.png',
'//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/phone2.png',
'//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/phone3.png',
'//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/phone4.png',
'//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/phone5.png',
'//raw.githubusercontent.com/ruisoftware/jquery-rsSliderLens/master/src/demo/phone6.png'
]).each(function() {
$('<img>').attr('src', this);
});
Also see: Tab Triggers