ここに私の jsFiddle があります: http://jsfiddle.net/markrummel/vPcrX/
このコードは、Chrome、Firefox、Safari、および IE 10 で機能しますが、IE 7、8、または 9 では機能しません。
IE 10 の Developer Tool を使用してテストしましたが、IE 7、8、または 9 で最初に開いたときには機能しませんでした。しかし、Developer Tool を開いた後、IE 7、8、および 9 で機能し始めました。Microsoft の Virtual PCを介して古い IE ブラウザでもテストしましたが、ローテータは機能しません。
ここでページ全体を見ることができます: http://melaniejaderummel.com . ただし、削除されたjsFiddleでは機能しないため、問題は jQuery コードに限定されていると思います。
あなたが提供できるどんな助けも大歓迎です!
私のHTML:
<div id="testimonials">
<p data-testimonial="1">“Testimonial Content” – Julie S.</p>
<p data-testimonial="2">“Testimonial Content” – Melissa D.</p>
<!--repeated; 10 total testimonials-->
</div>
関連する CSS:
#testimonials p {display:none;}
そして最後に、これが私のjavascriptです:
$(document).ready(function () {
var shownTestimonials = [];
displayTestimonials(shownTestimonials);
function displayTestimonials(shownTestimonials) {
var totalTestimonials = 10;
console.log(shownTestimonials);
//console.log(shownTestimonials.length);
if (shownTestimonials.length == 0 || shownTestimonials.length == totalTestimonials) {
var shownTestimonials = [];
}
function getNewTestimonial(totalTestimonials) {
return Math.floor(Math.random() * totalTestimonials) + 1; //random number between 1 and 10
}
var currentTestimonial = $('#testimonials p.visible').attr('data-testimonial');
var newTestimonial = getNewTestimonial(totalTestimonials);
console.log(currentTestimonial);
if (currentTestimonial == null) {
$('#testimonials p[data-testimonial="' + newTestimonial + '"]').addClass('visible').fadeIn(700);
shownTestimonials.push(newTestimonial);
} else {
var newExists = 1;
while (newExists > -1) {
var newTestimonial = getNewTestimonial(totalTestimonials);
var newExists = $.inArray(newTestimonial, shownTestimonials)
console.log(newExists);
}
$('#testimonials p[data-testimonial="' + currentTestimonial + '"]').removeClass('visible').fadeOut(600);
setTimeout(function () {
$('#testimonials p[data-testimonial="' + newTestimonial + '"]').addClass('visible').fadeIn(700);
shownTestimonials.push(newTestimonial);
}, 700);
} //end else
setTimeout(function () {
displayTestimonials(shownTestimonials);
}, 12000);
} //end displayTestimonials();
}); //end $(document).ready