1

I'm trying to change ul translate with JS

<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. 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>
1
  • Will you upload this to jsfiddle.net? It's a great way and will speed up the time you get an answer. Commented Feb 12, 2014 at 22:42

1 Answer 1

1

You need to extract the number from inside translateX(...) in the original style.

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)';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.