Kan man også hente img title?
Hejsa,Jeg har følgende jquery kode som egentlig gør det den skal, nemlig at hente "img attribute alt" ud og skriver det i en div på siden.
Jeg vil dog gerne have den til at hente "img attribute title" også.
Er det muligt?
(function ($) {
$.fn.gallery = function () {
var $root = $(this),
$control = $root.find(".control"),
$back = $control.find(".back"),
$next = $control.find(".next"),
$counter = $control.find(".counter"),
$stage = $root.find(".stage"),
$scroll = $stage.find("ul"),
$lists = $stage.find("li"),
$imgs = $lists.find("img"),
$description = $root.find(".description"),
Btn = new Object(),
Flick = new Object(),
Init = new Object();
Btn = {
inview: 0,
set: function () {
$lists.removeClass("inview inmotion");
$lists.eq(Btn.inview).removeClass("ahead behind").addClass("inview inmotion");
$lists.eq(Btn.inview - 1).addClass("behind inmotion");
$lists.eq(Btn.inview + 1).addClass("ahead inmotion");
},
next: function () {
Flick.reset();
if (Btn.inview > $lists.length - 2) {
return;
}
Btn.inview += 1;
var _text = $lists.eq(Btn.inview).find("img").attr("alt");
Btn.set();
Btn.text(_text);
Btn.rim();
Btn.counter();
},
back: function () {
Flick.reset();
if (Btn.inview === 0) {
return;
}
Btn.inview -= 1;
var _text = $lists.eq(Btn.inview).find("img").attr("alt");
Btn.set();
Btn.text(_text);
Btn.rim();
Btn.counter();
},
text: function (str) {
$description.text(str);
},
rim: function () {
$back.removeClass("rim");
$next.removeClass("rim");
if (Btn.inview === 0) {
$back.addClass("rim");
} else if (Btn.inview > $lists.length - 2) {
$next.addClass("rim");
}
},
counter: function () {
var _counter = Btn.inview + 1 + "/" + $lists.length;
$counter.text(_counter);
}
};
Flick = {
startX: 0,
moveX: 0,
start: function (event) {
Flick.startX = event.originalEvent.touches[0].pageX;
},
move: function (event) {
event.preventDefault();
Flick.moveX = event.originalEvent.touches[0].pageX - Flick.startX;
Flick.scroll();
},
end: function (event) {
if (Flick.moveX < -50) {
Btn.next();
} else if (Flick.moveX > 50) {
Btn.back();
} else {
Flick.reset();
}
},
scroll: function () {
var _x = Math.floor(Flick.moveX / $stage.width() * 100);
$lists.eq(Btn.inview).css(Flick.css(_x));
$lists.eq(Btn.inview + 1).css(Flick.css(100 + _x));
if (Btn.inview === 0) {
return;
}
$lists.eq(Btn.inview - 1).css(Flick.css(-100 + _x));
},
css: function (pos) {
var _style = {
"-webkit-transform": "translate3d(" + pos + "%,0,0)",
"-moz-transform": "translate3d(" + pos + "%,0,0)",
"-webkit-transition": "none",
"-moz-transition": "none"
};
return _style;
},
reset: function () {
$lists.removeAttr("style");
}
};
Init = {
loaded: false,
set: function () {
var _$first = $lists.eq(0),
_text = _$first.find("img").attr("alt"),
_loaded = false,
_timer = setTimeout(function () {
Init.load(_text);
}, 3500);
$lists.addClass("ahead");
_$first.removeClass("ahead").addClass("inview inmotion");
$imgs.bind("load", function () {
clearTimeout(_timer);
Init.load(_text);
});
},
load: function (_text) {
if (Init.loaded) {
return;
}
$root.addClass("loaded");
$next.bind("click", Btn.next);
$back.bind("click", Btn.back);
$scroll.bind("touchstart", Flick.start);
$scroll.bind("touchmove", Flick.move);
$scroll.bind("touchend", Flick.end);
$scroll.bind("touchcancel", Flick.reset);
Btn.text(_text);
Btn.rim();
Btn.counter();
Init.loaded = true;
}
};
Init.set();
};
}(jQuery));
//Carsten