1

See here https://jsfiddle.net/97Lahmoh/ OR http://www.w3schools.com/code/tryit.asp?filename=FB8TE2KSHGZ5

basically I want to use jquery ui toggle slide animation without any jquery and plugins. this is jquery code which does the work.

$( "#effect" ).toggle("slide", {direction: "left"}, 500);

how to use it on pure javascript code? I'm not good at animations.

5
  • 1
    why you convert to javascript any reason behind on this question? Commented Dec 29, 2016 at 10:13
  • I want to use jquery ui toggle slide animation without any jquery and plugins you can't use jquery without jquery Commented Dec 29, 2016 at 10:14
  • Can anyone convert it to pure javascript animation? - yes, you'd have to ask a programmer to do it for you - don't ask on SO for a programmer to do it for you Commented Dec 29, 2016 at 10:15
  • what I want is pure javascript animation without jquery. It's mean I want (toggle slide animation) in pure javascript code. Commented Dec 29, 2016 at 10:16
  • Possible duplicate of Convert Jquery slidetoggle code to Javascript Commented Dec 29, 2016 at 10:33

2 Answers 2

2

You can use css transition with position property.

try this one:

function toggle() {
  var div1 = document.getElementById("div1");
  if (document.getElementsByClassName("hide").length == 0) {
    div1.className = "test hide";
  } else {
    div1.className = "test show";
  }

}
.test {
  width: 200px;
  height: 100px;
  background-color: #2354A4;
  transition: left 2s;
  position: relative;
  top: 0px;
  bottom: 0px;
  right: 0px;
}

.hide {
  left: -250px;
}

.show {
  left: 0px;
}
<div id="div1" class="test hide">

</div>

<button id="btnToggle" onclick="toggle()" type="button" name="btnToggle">TOGGLE</button>

Sign up to request clarification or add additional context in comments.

Comments

1

You can achive this by using css transition property.

Here is the JSFIDDLE

2 Comments

function runEffect() { var el = document.getElementById("effect"); if (el.classList) { el.classList.toggle("slideDiv"); } else { var classes = el.className.split(' '); var existingIndex = classes.indexOf("slideDiv"); if (existingIndex >= 0) classes.splice(existingIndex, 1); else classes.push("slideDiv"); el.className = classes.join(' '); } }
instead of toggle class I'll use it pure javascript. then it'll work. thanx for the css. jsfiddle.net/97Lahmoh/6

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.