;(
function
(a){
a.fn.LightBox =
function
(options){
var
defaults = {
controls :
true
}
var
opts = a.extend(defaults, options);
var
lb_wrap =
'<div class="lb_wrap"><div class="lightbox_bg"></div><div class="lightbox"><img src="loading.gif" class="lg_img" alt="jquery插件jquery.LightBox.js实现点击放大图片并左右点击切换效果(附demo源码下载)_jquery" ></div></div>'
;
a(
"body"
).append(lb_wrap);
if
(opts.controls){
a(
".lightbox"
).append(
'<p class="prev"></p><p class="next"></p>'
);
}
function
imgobj(obj1, obj2){
var
imgObj =
new
Image();
imgObj.src = obj1.attr(
"src"
);
var
margintop = 0 - (imgObj.height)/2;
obj2.css(
"margin-top"
,margintop);
}
this
.each(
function
(){
var
obj = a(
this
);
var
numpic = obj.find(
"li"
).length;
var
num = 0;
obj.find(
"img"
).click(
function
(){
var
src = a(
this
).attr(
"src"
);
a(
".lg_img"
).attr(
"src"
,src);
imgobj(a(
".lg_img"
), a(
".lightbox"
));
a(
".lb_wrap"
).fadeIn();
a(
".lg_img"
).fadeIn();
a(
".prev"
).fadeIn().siblings(
".next"
).fadeIn();
num = a(
this
).parent().index();
});
a(
".prev"
).click(
function
(){
if
(num == 0){
num = numpic;
}
var
src = obj.find(
"li"
).eq(num-1).find(
"img"
).attr(
"src"
);
a(
".lg_img"
).attr(
"src"
,src);
imgobj(a(
".lg_img"
), a(
".lightbox"
));
num--;
});
a(
".next"
).click(
function
(){
if
(num == numpic-1){
num = -1;
}
var
src = obj.find(
"li"
).eq(num+1).find(
"img"
).attr(
"src"
);
a(
".lg_img"
).attr(
"src"
,src);
imgobj(a(
".lg_img"
), a(
".lightbox"
));
num++;
});
a(
".lb_wrap"
).click(
function
(e){
var
e = e || window.event;
var
elem = e.target || e.srcElement;
while
(elem){
if
(elem.className && elem.className.indexOf(
'prev'
)>-1) {
return
;
}
if
(elem.className && elem.className.indexOf(
'next'
)>-1){
return
;
}
elem = elem.parentNode;
}
a(
this
).find(
"img"
).attr(
"src"
,
"loading.gif"
).hide();
a(
this
).find(
".prev"
).hide().siblings(
".next"
).hide();
a(
this
).fadeOut();
});
})
}
})(jQuery);