javascript - Jquery to change the value of an object -


how use jquery change value of object. have object , know selector, how change rgb value on click? i'm trying change pencolor. there data colors on 4 list items (yellow, green, blue, orange). when user clicks on yellow, js object changes object value?

var signaturepad = new signaturepad(canvas, {     minwidth: 2,     maxwidth: 5,     pencolor: "rgb(66, 133, 244)" });  var selectedcolor = $(e.currenttarget).data('color'); $('.initial').css('color', selectedcolor); 

and here's markup:

<ul class="global-color">   <li class="yellow-pick" data-color="#f8c90d"></li>   <li class="green-pick" data-color="#3dae49"></li>   <li class="orange-pick" data-color="#e87425"></li>   <li class="blue-pick" data-color="#009cc5"></li> </ul> 

jsfiddle demo

you can change .pencolor property of signaturepad during runtime (the api supports this). in order translate hex rgb() should use answer linked here person well

hextorgb adapted from: https://stackoverflow.com/a/5624139/1026459

function hextorgb(hex) {  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);  return result ? "rgb("+parseint(result[1], 16)+     ","+parseint(result[2], 16)+     ","+parseint(result[3], 16)+")"   : null; } 

so using , assigning property on click ends looking this:

$('.global-color li').click(function(){  $('.on').removeclass('on');//demo highlighting  var $t = $(this);  $t.addclass('on');//demo highlighting  var selectedcolor = $t.data('color');//read data  signaturepad.pencolor = hextorgb(selectedcolor);//assign pen color }); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -