JSTween library broken

谁说胖子不能爱 提交于 2019-12-12 01:09:30

问题


The JSTween library doesn't seem to perform a simple animation pulled from the library's tutorial. Using the following code, the alert box will show up after the allotted 1 second duration, but no animation will take place.

I must have set up the library wrong somehow, but I can't see the problem.

<html>
<head>

<style type="text/css">
#box 
{ 
    width: 16px;
    height: 16px;
}
</style>

<script type="text/javascript" src="jquery-1.10.1.js"></script>
<script type="text/javascript" src="jstween-1.1.js" ></script>
<script type="text/javascript" src="jstween-1.1.min.js" ></script>

<script type="text/javascript">
function animate() 
{
    $('#box').tween({ 
        width:{
        start: 16,
        stop: 200,
        time: 0,
        units: 'px',
        duration: 1,
        effect:'easeInOut',
        onStop: function(){ alert( 'Done!' ); }
        }
    }).play();
}
</script>
</head>

<body>

<div id="box">
<img src="image.png" onClick="animate()" />
</div>

</body>
</html>

Additional info: using Safari on 10.7.5. Code does not work in Chrome or Firefox either.


回答1:


For anyone who may read this in the future, I discovered the problem: the CSS element #box needs position: relative; as an attribute, otherwise the browser will hold the element in place by default.



来源:https://stackoverflow.com/questions/17317297/jstween-library-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!