简体   繁体   English

用纯javascript动画,没有jquery

[英]Animation with pure javascript, no jquery

I was using jquery/jquery-ui's slideDown() animation function for a particular task. 我正在使用jquery / jquery-ui的slideDown()动画函数来完成特定任务。 It now transpires that I will not be able to use jQuery in this project. 现在发现我将无法在这个项目中使用jQuery。 I also cant use YUI or any other libraries. 我也不能使用YUI或任何其他库。 So I wondering is there a way to perform a slideDown style animation using pure javascript? 所以我想知道有没有办法使用纯javascript执行slideDown风格的动画?

Edit: I have to do it without jQuery because I am using selenium to control a webpage and on this particular site adding jQuery to the page breaks event handlers for some reason. 编辑:我必须在没有jQuery的情况下这样做,因为我使用selenium来控制网页,并且在这个特定的网站上由于某种原因将jQuery添加到分页符事件处理程序。

You can do slides and animations using CSS3, eg 你可以使用CSS3做幻灯片和动画,例如

.slidable {
  position: relative;
  -webkit-animation: Slider 2s ease-in-out;
}
@-webkit-keyframes Slider {
  from {
    top: 0px;
  }
  to {
    top: 100px;
  }
}

Use -moz- for Firefox. 使用-moz-用于Firefox。 Javascript can do movements as well, just put them in timers, eg Javascript也可以做动作,只需将它们放在定时器中,例如

var top = 0;
window.Timeout(MoveSomething, 10);
function MoveSomething {
  var el = document.getElementById('moveme');
  top += 2;      
  el.style.top = top + 'px';
  if (top < 100) window.Timeout(MoveSomething, 10);
}

Just takes coding! 只需要编码!

The obvious answer is yes...quick question...couldn't you just do an ASYNC load of jQuery into the document and then use it after the fact, or can you not use it because of other limitations? 显而易见的答案是肯定的...快速问题...你不能只是在文档中加载一个ASYNC的jQuery,然后在事后使用它,或者你是否因为其他限制而不能使用它?

Worst case you could rip out the part you needed, but that doesn't make much sense. 最糟糕的情况是你可以撕掉你需要的部分,但这没有多大意义。 If you can edit any of the JS you could easily paste jQuery just above your code. 如果您可以编辑任何JS,您可以轻松地将jQuery粘贴到代码上方。

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

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