用js实现。点击图片的左边,去上一张;点击图片的右边,去下一张。
Jquery脚本在http://jquery.com/ 下载
Jquery实现比较简单
var imageOnclick = function(e, id, preid, nextid) {
if (e) {
var cursorper = (parseInt(e.clientX) – $(id).offset().left) / $(id).width();
if (cursorper < 0.5) {
if ($(preid).attr(‘href’) != null) {
window.location.href = $(preid).attr(‘href’);
}
} else {
if ($(nextid).attr(‘href’) != null) {
window.location.href = $(nextid).attr(‘href’);
}
}
} else {
return false;
}
}
其中:ID为albums的为img对象,ID为preLink的为上一张图片地址的隐藏域(hidden),ID为nextLink的为下一张图片地址的隐藏域(hidden)
两个图片地址是左右箭头图片。
效果:http://www.new0315.com/Image/Display?identifier=87571
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/222041.html原文链接:https://javaforall.net
