0

我使用 jquery.address() 通过 ajax 加载我的页面:

$.address.state('').init(function() {

// Initializes the plugin
$('#menu a').address();
$('#nextprev a').address();

}).change(function(event) {

// Loads the page content and inserts it into the content area
$.ajax({
    url: $.address.state() + event.path,
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      console.log(XMLHttpRequest.responseText);
    },
    success: function(data, textStatus, XMLHttpRequest) {
      $('title').html($('title', data).html());
      $.address.title(/>([^<]*)<\/title/.exec(data)[1]);
      $('#content').html($('#content', data).html());
      loadstuff();
      startAnimation();
    }
});

var startAnimation = function(data) {
... some animation going on here
});

目前代码调用ajax加载下一页后,通过startAnimation()飞入下一页。到目前为止,这真的很好。

但是我在#nextprev 中有一个#next 和一个#prev 元素。我要地址找出它们中的哪一个被点击,然后加载不同的函数(即startAnimation2())。

4

1 回答 1

0

您需要在标记属性(或隐藏的输入/本地 PC 内存)中定义当前动画索引,例如:

<input type="hidden" value="3" name="current-animation" />

然后获取值:

$('input[name="current-animation"]').val();

替代标记:

<div id="animation-data" data-current="3" data-animation="animation-1"></div>
于 2011-08-21T13:28:21.260 回答