我有一個點擊事件,在某些AJAX內容中動畫顯示到頁面上。事件完成後jquery undelegate點擊事件
一旦這個內容顯示出來,並且用戶點擊了激活該過程的相同鏈接,我現在想要反轉該過程並關閉當前打開的飛出內容。
目前打開的飛出是通過點擊「關閉」鏈接或點擊序列中的另一個飛出鏈接關閉的。如果用戶點擊當前的飛出鏈接,那麼我希望當前的飛行關閉。
// 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;
});
智能一個暱稱:) – RyanP13 2010-08-18 15:32:13
使用相同的代碼我如何等待,直到當前飛出是否打開新的飛出之前,如果點擊一個鏈接是不是當前的? – RyanP13 2010-08-18 15:34:17
@ RyanP13 - 你想排隊他們,或忽略其他''fly_out'點擊,而它的工作? – 2010-08-18 15:38:37