[英]Adding css property value to existing value with javascript
I'm trying to change ul translate with JS 我正在尝试用JS更改ul translation
<ul id="navigation" style="-webkit-transform: translateX(0px);"></ul>
by clicking on button 通过点击按钮
<input type="button" value=">" onclick="pomakDesno()" class="button"/>
But when I change it using onclick I would like with every click to increase it, in otherwords, add some value to already existing value. 但是,当我使用onclick对其进行更改时,我希望每次单击都可以增加它,换句话说,就是为已经存在的值添加一些值。 I have this code.
我有这个代码。 What am I doing wrong?
我究竟做错了什么?
<script>
function pomakDesno(){
var mvalue=document.getElementById('navigation').style.WebkitTransform;
var tvalue=111;
var zvalue= mvalue+tvalue;
document.getElementById('navigation').style.WebkitTransform='translateX(' + zvalue + 'px)';}
</script>
You need to extract the number from inside translateX(...)
in the original style. 您需要以原始样式从
translateX(...)
内部提取数字。
function pomakDesno(){
var mvalue=parseInt(document.getElementById('navigation').style.WebkitTransform;
var translateX = parseInt(mvalue.match(/translateX\((\d?)px\)/)[1], 10);
var tvalue=111;
var zvalue= mvalue+tvalue;
document.getElementById('navigation').style.WebkitTransform='translateX(' + zvalue + 'px)';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.