简体   繁体   English

javascript,css转换功能

[英]javascript, css transition functions

I have these buttons in html: 我在html中有这些按钮:

<a href="#" onClick="slideHome('EntireSite');">Home</a>
<a  href="#" onClick="slideAbout('EntireSite');">About Me</a>
<a href="#" onClick="slidePorto('EntireSite');">Portofolio</a>

As you see, these buttons call functions 如您所见,这些按钮调用函数

functions: 职能:

<script>
function slideHome(el){
var elem = document.getElementById(el);
elem.style.transition = "left 0.5s ease-in-out 0s";
elem.style.left = "0px";    
}


function slideAbout(el){
var elem = document.getElementById(el);
elem.style.transition = "left 0.5s ease-in-out 0s";
elem.style.left = "1100px";

}

these 2 work perfectly fine, but now the last function: 这两个工作正常,但现在是最后一个功能:

function slidePorto(el){
var elem = document.getElementById(el);
elem.style.transition = "top 0.5s ease-in-out 0s";
elem.style.top = "-400px";
elem.style.transition = "left 0.5s ease-in-out 1s";
elem.style.left = "1300px";     
}
</script>

This function needs to move down and to the left, as a result, the "slideHome" function get's a extra line of code to move it back as well. 该函数需要向下和向左移动,因此,“ slideHome”函数将获得一行额外的代码来将其移回。

The problem is, that in the "slidePorto"function, it skips the first transition, it moves, but not smoothly, so it quickly moves to the bottum, and then the transition to the left fires. 问题在于,在“ slidePorto”功能中,它跳过了第一个过渡,但它移动但不平稳,因此它迅速移至底部,然后过渡至左侧射击。 Same problem for the "slideHome" function when I want to move back to top:0px; 当我想回到top:0px时,“ slideHome”功能也有同样的问题;

How do I get these to transitions together? 如何使它们一起过渡? Thanks in advance! 提前致谢!

You can specify multiple transitions on an element before trigerring them by the script. 您可以在元素上指定多个过渡,然后再通过脚本对其进行分类。

This code specifies the transitions, then do the "top" part and after that ended the transition by the "left" transition part. 此代码指定过渡,然后执行“顶部”部分,然后在过渡之后由“左侧”过渡部分结束。

function slidePorto(el) {
    var elem = document.getElementById(el);
    elem.style.transition = "top 0.5s ease-in-out 0s,left 0.5s ease-in-out 1s";
    elem.style.top = "-400px";
    elem.style.left = "1300px";
}

NB: I don't understand why you specify -400px , but it works for every value you desire. 注意:我不明白为什么指定-400px ,但是它适用于您想要的每个值。

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

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