Get value of slider while it's being moved?

Benjin

I'm messing around learning some basic front-end web technologies - Bootstrap, jQuery, HTML5 canvas - and I wanted to be able to update the dimensions of a sinusoid I'm drawing as the slider moves, not when it's released (how it currently works).

<input type="range" id="ampSlider" min="-200" max="200" step="5" onchange="refreshGraph()">
<input type="range" id="freqSlider" min="1" max="400" step="5" onchange="refreshGraph()">
<canvas id="graphCanvas" width="1000" height="600"></canvas>

<script>
    drawShape();
    drawGraph(200, 150);
    $("#ampSlider").val(200);
    $("#freqSlider").val(150);

    function refreshGraph()
    {
        console.log($("#ampSlider").val());
        drawGraph($("#ampSlider").val(), $("#freqSlider").val());
    }

    function drawGraph(amp, freq)
    {
        console.log("Drawing: " + amp + " | " + freq);
        var canvas = document.getElementById('graphCanvas');
        var context = canvas.getContext('2d');
        context.clearRect(0, 0, canvas.width, canvas.height);
        var y = canvas.height/2;
        context.lineWidth = 10;
        context.beginPath();
        context.moveTo(0, y);

        for(n = 0; n < canvas.width; n += 5)
        {
            context.lineTo(n, amp * Math.sin(Math.PI * n / freq) + y);
        }

        context.stroke();
    }
</script>
lucas

use oninput instead of onchange

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Get value from jQuery slider while it's moving

Slider value doesn't update the value unless it's moved

Get slider's value jQuery

get value of slider with (change) of particular slider while using multiple sliders

immutable value is still being moved

Get Angular Material v2 slider's value while sliding

Is there anyway to grab the default value of the slider handle if it is not moved?

Powershell popup while file is being moved

How do I get the 'Value' property from a MSAccess Form textBox while it's being edited?

Vuetify - restrict minimum value a slider can be moved to in v-slider

How to prevent a value from being moved?

get value of slider in typescript

Angular's ng-class is not updating while the value being evaluated is

How to read every value of a UISlider regardless of how quickly the slider is moved?

How to determine if the slider is moved(or its value has changed)

How to get the maximum rate (frequency) at which a slider can be moved?

Get duration of video while it's being recorded with AVAssetWriter

Slider values not being updated as the value increases

Get label of slider to move with slider value

The value gets copied instead of being moved. Why?

How to identify a database when it's being moved to another server/instance

How to get the value of a slider in ApplescriptObjC?

Mat Slider value not getting updated while sliding

"use of moved value" when matching while merging two vectors

Unity - set slider value if it isn't being dragged?

Check if slider have been moved

Why slider handle can not be moved?

How can you update a textarea's value dynamically while still being able to edit it - React

Borrow of moved value error, but the value shouldn't have moved, because it's borrowed

TOP Ranking

HotTag

Archive