On this page我有一個jQuery彈出窗口和縮略圖可調整大小的圖像。如果我將鼠標懸停在縮略圖上,圖像的大小將完美調整。另外,當我點擊頁腳中的大型黃色電視按鈕「QuickBook TV」時,彈出窗口會完全按照我的意願顯示。內容通過AJAX加載後,jQuery不起作用
但是,當我點擊「Next」或「Prev」按鈕時,AJAX用於加載新內容,並且我的jQuery不再用於彈出窗口或縮略圖圖像。我搜索了一些論壇尋找關於這個問題的信息,但由於對jQuery的知識有限,我一直無法理解我需要做什麼。
以下是彈出的jQuery
$(document).ready(function() {
$(".iframe").colorbox({ iframe: true, width: "1000px", height: "500px" });
$(".inline").colorbox({ inline: true, width: "50%" });
$(".callbacks").colorbox({
onOpen: function() { alert('onOpen: colorbox is about to open'); },
onLoad: function() { alert('onLoad: colorbox has started to load the targeted content'); },
onComplete: function() { alert('onComplete: colorbox has displayed the loaded content'); },
onCleanup: function() { alert('onCleanup: colorbox has begun the close process'); },
onClosed: function() { alert('onClosed: colorbox has completely closed'); }
});
//Example of preserving a JavaScript event for inline calls.
$("#click").click(function() {
$('#click').css({ "background-color": "#f00", "color": "#fff", "cursor": "inherit" }).text("Open this window again and this message will still be here.");
return false;
});
});
這是縮略圖的jQuery
$(function() {
var xwidth = ($('.image-popout img').width())/1;
var xheight = ($('.image-popout img').height())/1;
$('.image-popout img').css(
{'width': xwidth, 'height': xheight}
); //By default set the width and height of the image.
$('.image-popout img').parent().css(
{'width': xwidth, 'height': xheight}
);
$('.image-popout img').hover(
function() {
$(this).stop().animate({
width : xwidth * 3,
height : xheight * 3,
margin : -(xwidth/3)
}, 200
); //END FUNCTION
$(this).addClass('image-popout-shadow');
}, //END HOVER IN
function() {
$(this).stop().animate({
width : xwidth,
height : xheight,
margin : 0
}, 200, function() {
$(this).removeClass('image-popout-shadow');
}); //END FUNCTION
}
);
});
十分感謝花花公子的幫助。大問題,圖片縮略圖問題已解決。但Colorbox popop問題仍然存在。你能指導我如何在頁面加載和Ajax請求中調用它? –
@AwaisImran將其移動到一個單獨的功能(如在我的答案的後半部分建議),然後調用到位那些行你'$(文件)中。就緒()'函數來處理頁面加載。 jQuery中的所有AJAX函數都有一個(可選的)成功回調函數,當響應成功時它將執行。然後你只需要調用裏面的函數;如果你在你的問題中包含了相關的AJAX調用,我可以更具體一些。 –
嘿安東尼,我已修復彈出問題。我將這個腳本改爲「$(document).ready(function(){」to this line「$(document).on('mouseover','.iframe',function(){」,它對我來說工作正常。非常感謝您一直以來的支持。我希望我能成爲jQuery的專家喜歡你:) –