我想在jQuery中創建一個徽標的「牆」,就像在https://www.squarespace.com/網站上的「TRUSTED BY THE WORLD'S BEST」部分所示。網格中的隨機標誌
同樣的事情:8個標誌與淡入淡出。
我可以幫忙嗎?
<div class="client-logos-grid">
<a href="" class="client-logo"><img src="" alt=""></a>
<a href="" class="client-logo"><img src="" alt=""></a>
<a href="" class="client-logo"><img src="" alt=""></a>
<a href="" class="client-logo"><img src="" alt=""></a>
<a href="" class="client-logo"><img src="" alt=""></a>
<a href="" class="client-logo"><img src="" alt=""></a>
<a href="" class="client-logo"><img src="" alt=""></a>
<a href="" class="client-logo"><img src="" alt=""></a>
</div>
我開始使用此:https://jsfiddle.net/vc43mzxL/1/
$('document').ready(function() {
var curIndex = 0;
var src = ['http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg', 'http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg', 'http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg'];
var fadeTimeInMilliseconds = 2000;
var waitTimeInMilliseconds = 5000;
$(document).ready(function() {
switchImageAndWait(true);
});
function switchImageAndWait(fadeOut2) {
if (fadeOut2) {
setTimeout(fadeOut, waitTimeInMilliseconds);
} else {
var index = Math.floor((Math.random() * src.length))
if (curIndex == index) {
index++;
if (index >= src.length) {
index -= 8;
}
}
curIndex = index;
$(".client-logo img").attr("src", src[index]);
fadeIn();
}
}
function fadeOut() {
$(".client-logo img").fadeTo(fadeTimeInMilliseconds, 0, function() {
switchImageAndWait(false);
});
}
function fadeIn() {
$(".client-logo img").fadeTo(fadeTimeInMilliseconds, 1, function() {
switchImageAndWait(true);
});
}
});
看起來你忘了添加你的JS代碼..? – Teemu
你需要提供你的js代碼 –
@CBroe是的,但我的評論是更有禮貌的方式來表達這個想法。最終似乎是一個錯誤的假設,OP似乎有一個嘗試。 – Teemu