I have this jquery
开发者_运维技巧$('#1').fancybox({
'width': '50%',
'height': '90%',
'autoDimensions': false,
'type': 'ajax',
'ajax': {
dataFilter: function(data) {
return $(data).find('.news:first')[0];
}
}
});
$('#2').fancybox({
'width': '50%',
'height': '90%',
'autoDimensions': false,
'type': 'ajax',
'ajax': {
dataFilter: function(data) {
return $(data).find('.news:eq(1)')[0];
}
}
});
is there a possibility combine these 2 into 1
THNX
Your biggest problem is the dataFilter
but you could try something like this:
$('#1, #2').each(function(i, el) {
$(el).fancybox({
'width': '50%',
'height': '90%',
'autoDimensions': false,
'type': 'ajax',
'ajax': {
dataFilter: function(data) {
return $(data).find('.news:eq(' + i + ')')[0];
}
}
});
});
Like this?
$('#1, #2').fancybox({
'width': '50%',
'height': '90%',
'autoDimensions': false,
'type': 'ajax',
'ajax': {
dataFilter: function(data) {
return $(data).find('.news:eq(1)')[0];
}
}
});
You can combine selectors as you do in CSS by separating them with commas.
Edit:
:first
is just a shorthand for :eq(0)
, so the only differance between your settings were the selectors. Quote from jQuery docs:
The :first pseudo-class is equivalent to :eq(0).
精彩评论