2017-10-03 2 views
0

スライダ入力を使用して、pngのCSSフィルタ(色相が正確になるように)を変更しようとしています。 「WEBKIT-FILTER:色相回転(未定義度)」Sliderを使用して画像を変更するCSSフィルタをJavaScriptで使用する

ありがとうございました!

function hueFunction(hueVal) { 
 
    var setAs = hueVal + "deg" 
 
    document.getElementById("lgImage").setAttribute("style", "-webkit-filter:hue-rotate(" + setAs + ")") 
 
}
<input type="range" data-default="0" value="0" min="0" max="360" step="1" id="hue-rotate" oninput="hueFunction(this.hueVal)"> 
 

 
<br/> 
 

 
<img src="https://campstoregear.com/wp-content/uploads/2017/09/summer-camp-2018-apparel-design-CD1816-Primary.png" id="lgImage">

答えて

2

変更oninput="hueFunction(this.hueVal)"

function hueFunction(hueVal) { 
 
    var setAs = hueVal + "deg" 
 
    document.getElementById("lgImage").setAttribute("style", "-webkit-filter:hue-rotate(" + setAs + ")") 
 
}
<input type="range" data-default="0" value="0" min="0" max="360" step="1" id="hue-rotate" oninput="hueFunction(this.value)"> 
 

 
<br/> 
 

 
<img src="https://campstoregear.com/wp-content/uploads/2017/09/summer-camp-2018-apparel-design-CD1816-Primary.png" id="lgImage">

+0

あなたは素晴らしいですoninput="hueFunction(this.value)"へ:

は、ここに私のコードです!それがトリックでした。束をありがとう。 – user3491000

+0

これはなぜIDの代わりにクラスでは動作しないのですか? "getElementByID"を "getElementsByClassName"と入れ替えても動作しません。 – user3491000

+0

'getElementById'は単一の要素を返します。' getElementsByClassName' - 要素の配列です。 'getElementsByClassName( 'youClassName')[0]' http://jsbin.com/piworezoco/edit?html,js,output –

関連する問題