2009-08-13 27 views
0

我想使用xml数据插入作为一个动画的变量,但我相当无知。我做错了什么,我有多远?jquery,xml和变量

$(document).ready(function(){ 
    $.ajax({ 
     type: "GET", 
     url: "data.xml", 
     dataType: "xml", 
     success: function(xml) { 
      $(xml).find('mon').each(function(){ 
       var top = $(this).find('positiontop').text(); 
       var opac = $(this).find('opacity').text(); 
       var dur = $(this).find('duration').text(); 
       $(".mon img").animate({ top: "'+top+'",opacity: '+opac+'}, '+dur+'); 
      }); 
     } 
    }); 
}); 

,这里是我的XML

<data> 
    <mon> 
     <positiontop>180</positiontop> 
     <opacity>0.6</opacity> 
     <duration>1500</duration> 
    </mon> 
..... 
.... 
</data> 

回答

0

使用这种微变片段应该帮助和对我的作品..

.MON { 的位置是:相对的; }

.mon img 
{ 
    position:relative;  
} 
</style> 

<div class="mon"> 
    <img src="my_image.gif" /> 
</div> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $.ajax({ 
      type: "GET", 
      url: "data.xml", 
      dataType: "xml", 
      success: function(xml) { 
       $(xml).find('mon').each(function() { 
        var positiontop = $(this).find('positiontop').text(); 
        var opac = $(this).find('opacity').text(); 
        var duration = $(this).find('duration').text(); 
        $(".mon img").animate({ top: positiontop, opacity: opac }, parseInt(duration)); 
       }); 
      } 
     }); 
    }); 
</script> 
+0

这确实有用,谢谢! 我是新来的网站,所以我如何给你代表? – Trip 2009-08-14 08:25:37

+0

不知道队友,盲目领导盲人在这里,我的第一天在网站上:-) – Kevin 2009-08-14 09:14:47

0

animate函数设置某种回调,你的代码将继续运行,这将极有可能.animate功能的X呼叫数目在运行同时。