文章详情页
关于设置obj的opacity,一直失败
浏览:57日期:2024-05-25 16:27:56
问题描述
var timer = null; function touming(obj,num){clearInterval(timer);timer = setInterval(function(){ var speed = (num - obj.style.opacity)*100/5; speed = speed>0 ? Math.ceil(speed) : Math.floor(speed); if(obj.style.opacity == num){clearInterval(timer); }else{obj.style.opacity = obj.style.opacity + speed/100; }},100) } 想要通过传进去一个对象设置它的opacity,结果一直失败.经过调试发现只有第一次的时候能够成功设置,之后每次进else设置之后对象的opacity的值并没有改变.是为什么呢?
问题解答
回答1:obj.style.opacity 的获取值是字符串,而非数字, 所以+号操作得不到你想要的值, parseFloat一下即可
上一条:移动端页面文字垂直居中兼容性问题下一条:聊天气泡背景图自适应问题
相关文章:
排行榜
