【问题标题】:Jquery, xml and variablesJquery、xml 和变量
【发布时间】:2009-08-13 21:13:09
【问题描述】:

我正在尝试使用 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>

【问题讨论】:

    标签: jquery xml variables


    【解决方案1】:

    使用这个稍微改变的 sn-ps 应该对我有帮助和工作..

    .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>
    

    【讨论】:

    • 确实有效,谢谢!。我是该网站的新手,如何为您提供代表?
    • 不知道伙计,盲人在这里带领盲人,我也是该网站的第一天 :-)
    【解决方案2】:

    animate 函数设置了某种回调,您的代码将继续运行,这很可能会同时运行 x 个 .animate 函数调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      • 2012-04-30
      • 1970-01-01
      相关资源
      最近更新 更多