Experimenting with creating titles that fade in and out on a landing page only once without repeating. I attempted to incorporate a counter variable to ensure the titles stop looping after displaying all items in an array. This method allows for easy addition of new texts without adjusting item numbers manually.
// Stop loop after displaying last title in array
// +++++++++++++++++++ changeTitle
var titles = ["title zero", "title one", "title two", "title three",
"title four", "title n"
];
function changeTitle() {
var ct = $("#title").data("term") || 0;
$("#title").data("term", ct == titles.length - 1 ? 0 : ct + 1)
.text(titles[ct])
.fadeIn(200)
.delay(500)
.fadeOut(200, changeTitle);
}
$(changeTitle);