简体   繁体   English

jQuery将幻灯片动画切换为纯JavaScript动画

[英]jquery toggle slide animation to pure javascript animation

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

basically I want to use jquery ui toggle slide animation without any jquery and plugins. 基本上我想使用没有任何jquery和插件的jquery ui切换幻灯片动画。 this is jquery code which does the work. 这是工作的jQuery代码。

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

how to use it on pure javascript code? 如何在纯JavaScript代码上使用它? I'm not good at animations. 我不擅长动画。

You can use css transition with position property. 您可以将CSS过渡与position属性一起使用。

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> 

You can achive this by using css transition property. 您可以通过使用css transition属性来实现。

Here is the JSFIDDLE 这是JSFIDDLE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM