如何使用JavaScript控制图片的亮度,对比度 等功能
如何使用JavaScript控制图片的亮度,对比度 等功能
比如点击按钮 让图片的亮度增加 怎样用javascript实现
------解决方案--------------------JS和CSS的滤镜配合应该可以实现.
------解决方案--------------------
<script language=javascript>
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
function nereidFade(object, destOp, rate, delta){
if (!document.all)
return
if (object != "[object]"){
setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
return;
}
clearTimeout(nereidFadeTimers[object.sourceIndex]);
diff = destOp-object.filters.alpha.opacity;
direction = 1;
if (object.filters.alpha.opacity > destOp){
direction = -1;
}
delta=Math.min(direction*diff,delta);
object.filters.alpha.opacity+=direction*delta;
if (object.filters.alpha.opacity != destOp){
nereidFadeObjects[object.sourceIndex]=object;
nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
}
}
</script>
<img src="http://www.hack518.net/test.gif" border=0 onMouseOut=nereidFade(this,50,10,2) onMouseOver=nereidFade(this,100,10,2) style="FILTER: alpha(opacity=40)">
这个是鼠标经过时亮度变化的
------解决方案--------------------
<body onLoad="fade()">
<img src="1.gif" name="u" border=0
alt="Image" style="filter:alpha(opacity=0)" width="330" height="400">
<script language="JavaScript">
var b = 1;
var c = true;
function fade(){
if(document.all);
if(c == true) {
b++;
}
if(b==100) {
b--;
c = false
}
if(b==10) {
b++;
c = true;
}
if(c == false) {
b--;
}
u.filters.alpha.opacity=0 + b;
setTimeout("fade()",50);
}
</script>
</body>
</html>
这个是自动改变的,你可以改成手动的
------解决方案--------------------
<script language="javascript">
var b = 1;
var c = 1;
var d;
function blur1()
{ var btn = document.getElementById("iimg");
var aa = document.getElementById("aa");
if(c!= 100) {
b++;
c=b;
}
d=0+b;
btn.style.filter="Alpha(Opacity="+d+")";
aa.value=d;
}
function focus1()
{
var btn = document.getElementById("iimg");
var aa = document.getElementById("aa");
if(c!= 00) {
b--;
c=b;
}
d=0+b;
btn.style.filter="Alpha(Opacity="+d+")";
aa.value=d;
}
</script>
<img src="http://www.hack518.net/test.gif" border=0 id="iimg" style="filter:alpha(opacity=100);"> <input id="btn" type="button" value="button" onclick="blur1()">
<input id="btn1" type="button" value="button1" onclick="focus1()"></div>
<input type="text" value="" id="aa">
------解决方案--------------------上面这个在IE中测试通过
------解决方案--------------------用滤镜的效果,不过好象只有ie支持.
------解决方案--------------------^_^