javascript - Input range returns undefined -
problem
so, problem <input type="range"> returns undefined on change. in changecheck(), checking <input type="range"> changed.in addbrightness(), outputting value of <input type="range">, when ever changed.
javascript
// variables var canvas = $('#editor')[0]; var ctx = canvas.getcontext('2d'); var img = new image(); img.crossorigin = ''; img.src = ''; var file = $('.file'); var open = $('.open'); var fileopen = $('.file-open'); var control = $("input[type=range]"); var brightness = $('.brightness'); // main $(document).ready(function() { $(img).on('load', imgload); $(file).on('click', dropdown); $(open).on('click', openfile); $(fileopen).on('change', getpath); $(control).on('change', checkchange); }) // check change function checkchange() { if($(this).parent().hasclass('brightness')) { addbrightness(); } } // add brightness function addbrightness(val) { var value = $('brightness').val(); console.log(value); /*caman('#editor', function () { this.brightness(value); this.render(); });*/ } // dropdown function dropdown() { $(this).children('ul').slidetoggle(); } // open file function openfile() { $(fileopen).click(); } // file path function getpath(e) { img.src = url.createobjecturl(e.target.files[0]); ctx.imagesmoothingenabled = false; imgload(); } // load img function imgload() { if(img.width > 800) { img.width = 800; if(img.height > 800) { img.height = 800; canvas.width = img.width; canvas.height = img.height; ctx.drawimage(img, 0, 0, img.width, img.height); } } } html
<!doctype html> <html> <head> <title></title> <!-- stylesheets --> <link rel="stylesheet" type="text/css" href="assets/css/large.css" media="(min-width:800px)"> <!-- fonts --> <link href="https://fonts.googleapis.com/css?family=roboto:400,500" rel="stylesheet"> <!-- favicon --> </head> <body> <nav> <ul> <li class="file"><i class="fa fa-file-o" aria-hidden="true"></i> file <ul> <li class="open"><i class="fa fa-folder-open-o" aria-hidden="true"></i> open</li> <li class="save"><i class="fa fa-floppy-o" aria-hidden="true"></i> save</li> <li class="exit"><i class="fa fa-sign-out" aria-hidden="true"></i> exit</li> </ul> </li> </ul> </nav> <div class="container"> <center> <canvas id="editor"></canvas> </center> <div class="controls-container"> <!-- brightness --> <div class="brightness control"> <h3>brightness</h3> <input type="range" value="50" min="0" max="100"> </div> <!-- contrest --> <div class="contrast control"> <h3>contrast</h3> <input type="range" value="50" min="0" max="100"> </div> <!-- exposure --> <div class="exposure control"> <h3>exposure</h3> <input type="range" value="50" min="0" max="100"> </div> <!-- sharpen --> <div class="sharpen control"> <h3>sharpen</h3> <input type="range" value="0" min="0" max="100"> </div> </div> </div> <input type="file" class="file-open"> <!-- scripts --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/camanjs/4.0.0/caman.full.min.js"></script> <script src="https://use.fontawesome.com/e99695fe86.js"></script> <script src="assets/js/main.js"></script> </body> </html>
you not selecting input brightness correctly.
var value = $('.brightness>input[type="range"]:first').val(); will work.
Comments
Post a Comment