Есть ли способ объединить все это, чтобы уменьшить количество javascript?Объединение функций jQuery/JavaScript
$(document).ready(function() {
$(".individualImagebox img").bind("click", function()
{
var src = $(this).attr("src");
if (src.search(/Red\.jpg$/) >= 0) return;
// Removes the red overlay from the images folder
$('.individualImagebox img').attr("src", function() {
var thisSRC = $(this).attr("src");
return thisSRC.replace(/Red\.jpg$/, ".jpg");
});
// Adds the red overlay from the images folder
$(this).attr("src", src.replace(/\.jpg$/, "Red.jpg") );
});
});
function ShowHide(index) {
var itemSelector = ".name:eq(" + index + ")";
$(".name .bio").fadeOut();
$(".name").not(itemSelector).fadeOut();
$(itemSelector).animate({"height": "show"}, { duration: 500 });
$(itemSelector + " .bio").animate({"height": "show"}, { duration: 500 });
}
Есть ли «.jpg» изображение? Если нет, почему бы просто не удалить атрибут src? – bpierre
.jpg - изображение –
Хорошо, я обновил свой ответ. – bpierre