简体   繁体   English

从html5会话存储中读取值并在动画中使用不起作用

[英]Reading a value from html5 session storage and using in animation not working

I am having this trivial issue with animation and wonder if I am plugging things the right way. 我对动画有这个微不足道的问题,并且想知道我是否正确地插入了东西。 I would appreciate it if you can share your thoughts on this. 如果您能分享您的想法,我将不胜感激。 on JQuery initialization, I am saving a value as string via 'sessionStorate()' which I am then trying to use it for animating a div. 在JQuery初始化时,我通过'sessionStorate()'将值保存为字符串,然后我尝试使用它来设置div的动画。 Here is my code: 这是我的代码:

  $(document).ready(function()
  {
     sessionStorage.setItem('topVal','200');

     $("#myDiv").animate({

         'top' : sessionStorage.topVal
      },1000, function()
      {
          alert("ANIMATION DONE");
      });   
  });

If I to hard code the value instead of calling the 'sessionStorage.topVal'then div animates without any issues otherwise it doesn't. 如果我硬编码值而不是调用'sessionStorage.topVal'then div动画而没有任何问题,否则它不会。 My utmost thoughts were that things are being fired up way too fast and therefore the animate() function is not able to catch the 'sessionStorage.topVal'. 我最大的想法是事情被激起的速度太快,因此animate()函数无法捕获'sessionStorage.topVal'。 I wonder if I should employ a setTimeOut() to delay or just use delay(). 我想知道是否应该使用setTimeOut()来延迟或只使用delay()。 I am not certain whether these are good practices or there are other ways to get it going. 我不确定这些是好的做法还是有其他方法可以实现。 Thank you for your help. 谢谢您的帮助。

Works just fine for me. 对我来说工作得很好。

See http://jsfiddle.net/GuHdf/ http://jsfiddle.net/GuHdf/

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

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