我創建(從網上找到其他腳本幫助)的幻燈片腳本,變成其他圖像懸停時會爲灰度並暫停在同一時間幻燈片外部圖像時。問題是,當我將鼠標懸停在其中一張不屬於幻燈片的圖片上時,我無法讓它們淡入淡出。我已經嘗試了很多事情來解決這個問題,包括增加在現有的圖像所需要的灰度圖像,但我不能讓看起來一樣的,所以它的一種毫無意義的影響。在幻燈片圖像褪色徘徊
這種情況的代碼如下(我道歉,如果這是爲Javascript一團糟,我還是個新手):
如果// Holds the alt description of an image
var desc;
// Used to try to solve problem
var bgimg;
var bgli;
var current;
$(document).ready(function() {
//Execute the slideShow, set to 3 seconds for each images
slideShow(1000);
current = $('ul.slideshow li.show');
});
$(window).focus(function() {
timer = setInterval('gallery()', speed);
});
$(window).blur(function() {
clearInterval(timer);
});
function slideShow(speed) {
//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');
//Call the gallery function to run the slideshow
var timer = setInterval('gallery()', speed);
desc = $('ul.slideshow li.show').find('img').attr('alt');
//pause the slideshow on mouse over
$('img.color').hover(
function() {
clearInterval(timer);
$('#caption').stop().animate({'height': '70px'}, 1000);
cptxt(desc);
if (this.id == "img6" || this.id == "img7" || this.id == "img8" || this.id == "img9" || this.id == "img10") {
$(img1).stop().animate({"opacity": "0"}, "slow");
$(img2).stop().animate({"opacity": "0"}, "slow");
$(img3).stop().animate({"opacity": "0"}, "slow");
$(img4).stop().animate({"opacity": "0"}, "slow");
$(img5).stop().animate({"opacity": "0"}, "slow");
}
},
function() {
timer = setInterval('gallery()', speed);
$(img1).stop().animate({"opacity": "1"}, "slow");
$(img2).stop().animate({"opacity": "1"}, "slow");
$(img3).stop().animate({"opacity": "1"}, "slow");
$(img4).stop().animate({"opacity": "1"}, "slow");
$(img5).stop().animate({"opacity": "1"}, "slow");
$('#caption').stop().animate({'height': '0px'}, 1000);
$('#caption').html('');
});
}
function gallery() {
//if no IMGs have the show class, grab the first image
if ($('ul.slideshow li.show').length){
// if we found an item with the show class, assign it to current
current = $('ul.slideshow li.show');
} else {
// otherwise nothing is being shown, default to first element
$('#ul.slideshow li:first');
}
//trying to avoid speed issue
if (current.queue('fx').length == 0) {
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next;
// if there are additional elements (true when .length > 0)
if (current.next().length) {
next = current.next();
if (next.attr('id') == 'dark') {
bgli = next;
bgimg = next.find('img');
next = next.next();
}
} else {
// there is no next element, go back to first.
next = $('ul.slideshow li:first');
}
desc = next.find('img').attr('alt');
//Set the fade in effect for the next image, show class has higher z-index
next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000).removeClass('show');
}
}
function cptxt(altmsg) {
$('#caption').html(altmsg);
}
$(document).ready(function(){
$('img.color').hover(
function() {
if (this.id == "img1") {
$(img2).stop().animate({"opacity": "0"}, "slow");
$(img3).stop().animate({"opacity": "0"}, "slow");
$(img4).stop().animate({"opacity": "0"}, "slow");
$(img5).stop().animate({"opacity": "0"}, "slow");
$(img6).stop().animate({"opacity": "0"}, "slow");
$(img7).stop().animate({"opacity": "0"}, "slow");
$(img8).stop().animate({"opacity": "0"}, "slow");
$(img9).stop().animate({"opacity": "0"}, "slow");
$(img10).stop().animate({"opacity": "0"}, "slow");
}
else if (this.id == "img2") {
$(img1).stop().animate({"opacity": "0"}, "slow");
$(img3).stop().animate({"opacity": "0"}, "slow");
$(img4).stop().animate({"opacity": "0"}, "slow");
$(img5).stop().animate({"opacity": "0"}, "slow");
$(img6).stop().animate({"opacity": "0"}, "slow");
$(img7).stop().animate({"opacity": "0"}, "slow");
$(img8).stop().animate({"opacity": "0"}, "slow");
$(img9).stop().animate({"opacity": "0"}, "slow");
$(img10).stop().animate({"opacity": "0"}, "slow");
}
else if (this.id == "img3") {
$(img1).stop().animate({"opacity": "0"}, "slow");
$(img2).stop().animate({"opacity": "0"}, "slow");
$(img4).stop().animate({"opacity": "0"}, "slow");
$(img5).stop().animate({"opacity": "0"}, "slow");
$(img6).stop().animate({"opacity": "0"}, "slow");
$(img7).stop().animate({"opacity": "0"}, "slow");
$(img8).stop().animate({"opacity": "0"}, "slow");
$(img9).stop().animate({"opacity": "0"}, "slow");
$(img10).stop().animate({"opacity": "0"}, "slow");
}
else if (this.id == "img4") {
$(img1).stop().animate({"opacity": "0"}, "slow");
$(img2).stop().animate({"opacity": "0"}, "slow");
$(img3).stop().animate({"opacity": "0"}, "slow");
$(img5).stop().animate({"opacity": "0"}, "slow");
$(img6).stop().animate({"opacity": "0"}, "slow");
$(img7).stop().animate({"opacity": "0"}, "slow");
$(img8).stop().animate({"opacity": "0"}, "slow");
$(img9).stop().animate({"opacity": "0"}, "slow");
$(img10).stop().animate({"opacity": "0"}, "slow");
}
else if (this.id == "img5") {
$(img1).stop().animate({"opacity": "0"}, "slow");
$(img2).stop().animate({"opacity": "0"}, "slow");
$(img3).stop().animate({"opacity": "0"}, "slow");
$(img4).stop().animate({"opacity": "0"}, "slow");
$(img6).stop().animate({"opacity": "0"}, "slow");
$(img7).stop().animate({"opacity": "0"}, "slow");
$(img8).stop().animate({"opacity": "0"}, "slow");
$(img9).stop().animate({"opacity": "0"}, "slow");
$(img10).stop().animate({"opacity": "0"}, "slow");
}
},
function() {
$(img1).stop().animate({"opacity": "1"}, "slow");
$(img2).stop().animate({"opacity": "1"}, "slow");
$(img3).stop().animate({"opacity": "1"}, "slow");
$(img4).stop().animate({"opacity": "1"}, "slow");
$(img5).stop().animate({"opacity": "1"}, "slow");
$(img6).stop().animate({"opacity": "1"}, "slow");
$(img7).stop().animate({"opacity": "1"}, "slow");
$(img8).stop().animate({"opacity": "1"}, "slow");
$(img9).stop().animate({"opacity": "1"}, "slow");
$(img10).stop().animate({"opacity": "1"}, "slow");
}
);
});
對不起的代碼是可怕的:d。我花了幾分鐘試圖正確地佈置它,但很多都需要清理。
反正重申,懸停在幻燈片圖像truns其它影像的正確灰度。將鼠標懸停在其他圖標上不會將當前的幻燈片圖像變爲灰度。
任何幫助,將不勝感激。
按照要求,鏈接的jsfiddle http://jsfiddle.net/KXW4f/12/
幻燈片不會出現在它的工作,但我可能在該網站上選擇了一些錯誤的設置。無論如何,它在我的個人電腦上運行時都能正常工作,但總體思路已經顯示出來了。
目前,幻燈片圖像剛剛淡出爲白色背景(不透明度變爲0),但我想要的是灰度圖像顯示爲它淡出。謝謝。
你能提供工作的例子包括一些HTML標記? [的jsfiddle(http://jsfiddle.net) – Aletheios 2012-08-13 19:46:19
是啊,給我30分鐘和虐待嘗試垃圾的東西了快速 – Predz 2012-08-13 20:01:39
新增的jsfiddle在主後結束。幻燈片似乎不起作用,但也許我選擇了錯誤的設置。 – Predz 2012-08-13 21:27:48