我有一個小問題,我的JavaScript不工作在IE8。在Firefox,ie9和Chrome中運行良好,但不是ie8。我知道它與ie8中的文檔準備工作不同,但我無法找到答案。見下面的代碼。
// JavaScript Document
/* Set Opacity to 0 for all list items that do not have class show
This prevents the gallery animation from jumping around unexpectedly.
*/
function clearShowClass() {
setTimeout(timedInterval, 1000);
};
function timedInterval() {
$('ul.slideshow li').not('.show').css("opacity", 0);
clearShowClass();
};
function slideShow(speed) {
//Call the gallery function to run the slideshow
var timer = setInterval('gallery()', speed);
//Pause the slideshow on mouse over content
$('#footer, ul.slideshow').hover(
function() {
clearInterval(timer);
},
function() {
timer = setInterval('gallery()', speed);
});
} // End of slideshow
/* Slideshow gallery main images */
function gallery() {
//if no IMGs have the show class, grab the first image
var current = ($('ul.slideshow li.show') ? $('ul.slideshow li.show') : $('#ul.slideshow li.first'));
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption') ? $('ul.slideshow li:first') : current.next()) : $('ul.slideshow li:first'));
//Set the fade in effect for the next image, show class has higher z-index
next.css({
opacity: 4.0
}).addClass('show').animate({
opacity: 4.0
}, 1000);
// Hide the current image
current.animate({
opacity: 0.0
}, 1000).removeClass('show');
//if no thumbnails have the highlight class, grab the first thumbnail
var currentThumb = ($('#footer li.highlight') ? $('#footer li.highlight') : $('#footer li:first'));
var nextThumb = ($('#footer li:last').hasClass('highlight')) ? $('#footer li:nth-child(1)') : $('#footer li.highlight').next($('#footer li'));
nextThumb.addClass('highlight');
currentThumb.removeClass('highlight');
}; // End of Gallery
function thumbInt() {
for (i = 1; i <= $('ul.slideshow li').length; i++) {
$('#footer .thumbnail' + i).bind('click', {
iteration: i
}, function (event) {
$('ul.slideshow li').removeClass('show').css("opacity", 0).add($('ul.slideshow li:nth-child(' + event.data.iteration + ')').addClass('show').css("opacity", 0.0).animate({
opacity: 1.0
}, 1000));
$('#footer li').removeClass('highlight').add($('#footer li:nth-child(' + event.data.iteration + ')').addClass('highlight').add($('#footer li:nth-child(' + event.data.iteration + ') img')));
});
};
};
var prmEnd = Sys.WebForms.PageRequestManager.getInstance();
prmEnd.add_endRequest(function() {
thumbInt(); // Assign int to thumbnail list items
clearShowClass(); // Prevents multiple li having .show
$('#footer img').mouseover(
function() {
$(this).animate({
opacity: 3.7
})
});
$('#footer img').mouseout(
function() {
$(this).animate({
opacity: 0.7
})
});
//Set the opacity of all images to 0
$('ul.slideshow li').css({
opacity: 0.0
});
//Get the first image and display it (set it to full opacity)
$('ul.slideshow li:first').css({
opacity: 1.0
}).addClass('show');
//Get the first thumbnail and change css
$('#footer li:first').css({
opacity: 1.0
}).addClass('highlight');
});
$(document).ready(function() {
slideShow(6000);
thumbInt(); // Assign int to thumbnail list items
clearShowClass(); // Prevents multiple li having .show
$('#footer img').mouseover(
function() {
$(this).animate({
opacity: 3.7
})
});
$('#footer img').mouseout(
function() {
$(this).animate({
opacity: 0.7
})
});
});
此頁面的工作方式是在一個電臺用戶點擊按鈕來觸發_doPostBack並顯示一個圖片庫。問題是,當我做_dopostback文檔就緒代碼不再起作用,但這隻發生在ie8。我正在使用Sys.WebForms.PageRequestManager.getInstance();用於在更新面板中更新後運行的代碼。
謝謝。
您是否在控制檯中收到任何消息?你期望什麼樣的行爲,你看到了什麼? – Sampson 2012-04-27 13:46:02
請問您可以設置一個小提琴jsfiddle.net – mayrs 2012-04-27 13:46:36
如何將腳本插入到頁面中? http://stackoverflow.com/questions/747854/how-does-document-ready-work-in-ie-8 – LukeP 2012-04-27 13:47:15