I want to begin my onclick() function in javascript style.marginLeft=0
to be like start from '0px' to '-100%' to '-200%' and then at the end with '-200%', when It become '-200%' If you click It again, It will bring you back to .marginLeft='0'
Code on Jsfiddle
var x = document.getElementsByClassName('box')[0];
var u = -100;
function addMargin() {
var current = x.style.marginLeft = u + '%';
if (x.style.marginLeft == -200) {
x.style.marginLeft = '0';
} else {}
}
#container { display: inline-block; position: relative; width: 100%; height: 150px; white-space:
nowrap; overflow: hidden; }
.box { width: 100%; height: 150px;
display: inline-block; position: relative; }
.box:nth-child(1) { background: lightblue; }
.box:nth-child(2) { background: red; }
.box:nth-child(3) { background: green; }
<div id='container'>
<div class='box'>1</div>
<div class='box'>2</div>
<div class='box'>3</div>
</div>
<input type="button" value="Next>" onclick="addMargin()" />