我有一个点击事件,可以将一些 AJAX 内容动画到页面上。
一旦显示此内容并且用户单击激活该过程的相同链接,我现在想要反转该过程并关闭当前打开的飞出内容。
当前打开的飞出通过单击“关闭”链接或单击序列中的另一个飞出链接来关闭。如果用户单击当前飞出链接,那么我希望当前飞出关闭。
// Close fly out function
function closeFlyout() {
$('.fly_container').animate({
'right': '-332'
}, 300, 'swing', function() {
$(this).detach();
/* TODO: z-index issues in IE7, IE6
$('.dark_overlay').fadeOut(300, function() {
$(this).remove();
});
*/
});
};
$('.widget').delegate('.widget .fly_out', 'click', function() {
/*
TODO: z-index issues in IE7, IE6
$('body').prepend('<div class="dark_overlay" />');
*/
var $widget = $(this).closest('.widget');
var $flyOutIndex = $(this).index('.fly_out');
if ($flyOutIndex == 0) {
$flyOutURL = 'Content/HTMLSnippets/Flyouts/Priceassessment/product_order.htm';
} else if ($flyOutIndex == 1) {
$flyOutURL = 'Content/HTMLSnippets/Flyouts/PriceHistory/price_history_comparisons.htm';
} else if ($flyOutIndex == 2) {
$flyOutURL = 'Content/HTMLSnippets/Flyouts/PriceHistory/price_history_scenarios.htm';
} else if ($flyOutIndex == 3) {
$flyOutURL = 'Content/HTMLSnippets/Flyouts/PriceHistory/price_history_analysis.htm';
}
$('.current').removeClass('current');
$(this).addClass('current');
// Close any open flyouts
closeFlyout();
$.ajax({
type: 'GET',
url: DashboardApplicationRoot + $flyOutURL,
dataType: 'html',
cache: true,
success: function(data) {
$($widget).prepend(data);
$('.fly_container').animate({ 'right': '0' }, 300);
$('.scroll').jScrollPane();
$('.striped li:nth-child(even)').addClass('odd');
}
});
return false;
});
// Close fly out function
$('.widget').delegate('.fly_container .close', 'click', function() {
closeFlyout();
$('.current').removeClass('current');
return false;
});