从 alt 属性中提取标题并插入到 div 中
我目前在网站上使用相当可爱的 jQuery Slideviewer 1.1 插件,但想从显示的图像中提取 alt 属性,并在适当的时候将它们插入到 div 中。
该插件当前的代码如下所示,供参考:
jQuery(function(){
jQuery("div.svw").prepend("<img src='/template/theme/designdistillery/img/bg-portfolio-loading.gif' class='ldrgif' alt='loading...'/ >");
});
var j = 0;
var quantofamo = 0;
jQuery.fn.slideView = function(settings) {
settings = jQuery.extend({
easeFunc: "easeInOutExpo",
easeTime: 750,
toolTip: false
}, settings);
return this.each(function(){
var container = jQuery(this);
container.find("img.ldrgif").remove(); // removes the preloader gif
container.removeClass("svw").addClass("stripViewer");
var pictWidth = container.find("img").width();
var pictHeight = container.find("img").height();
var pictEls = container.find("li").size();
var stripViewerWidth = pictWidth*pictEls;
container.find("ul").css("width" , stripViewerWidth); //assegnamo la larghezza alla lista UL
container.css("width" , pictWidth);
container.css("height" , pictHeight);
container.each(function(i) {
jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><ul><\/ul><\/div>");
jQuery(this).find("li").each(function(n) {
jQuery("div#stripTransmitter" + j + " ul").append("<li><a title='" + jQuery(this).find("img").attr("alt") + "' href='#'>"+(n+1)+"<\/a><\/li>");
});
jQuery("div#stripTransmitter" + j + " a").each(function(z) {
jQuery(this).bind("click", function(){
jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
var cnt = -(pictWidth*z);
container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
return false;
});
});
// next image via image click 14/01/2009
jQuery("div#stripTransmitter" + j + " a").parent().parent().parent().prev().find("img").each(function(z) {
jQuery(this).bind("click", function(){
var ui = jQuery(this).parent().parent().parent().next().find("a");
if(z+1 < pictEls){
ui.eq(z+1).trigger("click");
}
else ui.eq(0).trigger("click");
});
});
jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
jQuery("div#stripTransmitter" + j + " a:first").addClass("current");
if(settings.toolTip){
container.next(".stripTransmitter ul").find("a").Tooltip({
track: true,
delay: 0,
showURL: false,
showBody: false
});
}
});
j++;
});
};
I am using the rather lovely jQuery slideviewer 1.1 plugin on a site at the moment, but would like to extract the alt attribute from images displayed and insert them into a div at the appropriate time.
The current code for the plugin is shown below for reference:
jQuery(function(){
jQuery("div.svw").prepend("<img src='/template/theme/designdistillery/img/bg-portfolio-loading.gif' class='ldrgif' alt='loading...'/ >");
});
var j = 0;
var quantofamo = 0;
jQuery.fn.slideView = function(settings) {
settings = jQuery.extend({
easeFunc: "easeInOutExpo",
easeTime: 750,
toolTip: false
}, settings);
return this.each(function(){
var container = jQuery(this);
container.find("img.ldrgif").remove(); // removes the preloader gif
container.removeClass("svw").addClass("stripViewer");
var pictWidth = container.find("img").width();
var pictHeight = container.find("img").height();
var pictEls = container.find("li").size();
var stripViewerWidth = pictWidth*pictEls;
container.find("ul").css("width" , stripViewerWidth); //assegnamo la larghezza alla lista UL
container.css("width" , pictWidth);
container.css("height" , pictHeight);
container.each(function(i) {
jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><ul><\/ul><\/div>");
jQuery(this).find("li").each(function(n) {
jQuery("div#stripTransmitter" + j + " ul").append("<li><a title='" + jQuery(this).find("img").attr("alt") + "' href='#'>"+(n+1)+"<\/a><\/li>");
});
jQuery("div#stripTransmitter" + j + " a").each(function(z) {
jQuery(this).bind("click", function(){
jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
var cnt = -(pictWidth*z);
container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
return false;
});
});
// next image via image click 14/01/2009
jQuery("div#stripTransmitter" + j + " a").parent().parent().parent().prev().find("img").each(function(z) {
jQuery(this).bind("click", function(){
var ui = jQuery(this).parent().parent().parent().next().find("a");
if(z+1 < pictEls){
ui.eq(z+1).trigger("click");
}
else ui.eq(0).trigger("click");
});
});
jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
jQuery("div#stripTransmitter" + j + " a:first").addClass("current");
if(settings.toolTip){
container.next(".stripTransmitter ul").find("a").Tooltip({
track: true,
delay: 0,
showURL: false,
showBody: false
});
}
});
j++;
});
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
第一个图像没有标题,因为标题仅在
onclick
之后显示。这可以通过插入来修复:
The first image has no caption because the caption displays only after
onclick
.This can be fixed by inserting:
它就像这样简单:
您希望什么时候发生这种情况?
It's as simple as:
When do you want this to happen?
图像通过此行在屏幕上激活(或进入视图),
您需要将此行修改为:
希望这有帮助......
The image is activated (or brought into view) on screen by this line
you need to modify this line to:
Hope this helps....
感谢大家的帮助!
我调整了 ekhaled 的脚本版本,使标题显示在该系列中第一张图像的下方,并为任何后续图像的标题提供了简单的淡入淡出效果 - 现在一切都运行得非常出色!
再次感谢 :)
Thanks for all the help guys!
I tweaked ekhaled's version of the script so that the caption was displayed underneath the first image in the series, as well as a simple fade effect for captions for any subsequent images - it's all working brilliantly now!
Thanks again :)