jQuery Address find out which element was clicked
I using jquery.address() to load my pages through 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
});
Currently after the code calls ajax to load the n开发者_StackOverflow社区ext page, the next page flies in through startAnimation(). That works really fine so far.
However I have a #next and a #prev element within #nextprev. I want address to find out which of them was clicked, and then load a different function (i.e. startAnimation2()).
You'll need to define in a markup attribute (or in a hidden input / local pc memory) the current animation index, someting like :
<input type="hidden" value="3" name="current-animation" />
and then get the value :
$('input[name="current-animation"]').val();
Alternative with markup :
<div id="animation-data" data-current="3" data-animation="animation-1"></div>
精彩评论