.stop() & .animate() jQuery functions into javascript

后端 未结 2 1088
囚心锁ツ
囚心锁ツ 2021-01-22 21:18

I want to learn the JavaScript as well. and looking the various jQuery functions to their equivalent JavaScript.

I want to convert this jQuery function to its equivalen

2条回答
  •  忘掉有多难
    2021-01-22 21:49

    you remind me when i started learning js , and then was very happy to find jquery , anyway i dont know why you are doing vice versa , but to answer you question

    Animation in javascript can be used using setInterval function with changing the top , left .. etc attributes over a very small amount of time ( usually 24 milli secconds ) which to the human eye are like a stream and not like seperate shots of positions , also you may consider using pure css3 , however a function like this may be used

     var position,ratio,time,mytimer;
    document.getElementById("hi").style.left=0;
    function animate_left(position,time)
    {
    ratio=position/time;
    if(parseInt(document.getElementById("hi").style.left)<=position)
    {
    document.getElementById("hi").style.left=(parseInt(document.getElementById("hi").style.left)+ratio*100).toString()+"px" 
    }
    
    else
    {
        clearInterval(mytimer)
    }
    }
    function animate(value1,value2)
    {
    mytimer=setInterval(function(){animate_left(value1,value2)},10) //where 10 is minimum smooth animation factor for human eye
    }
    animate(600,1000);
    

    http://jsfiddle.net/prollygeek/er67f/6/

提交回复
热议问题