Javascript 带链接的滑块图像
我有一个小问题,一个小jQuery脚本,我的幻灯片图像。脚本本身工作得很好,但我想为每个图像添加链接,已经尝试在Javascript 带链接的滑块图像,javascript,jquery,html,Javascript,Jquery,Html,我有一个小问题,一个小jQuery脚本,我的幻灯片图像。脚本本身工作得很好,但我想为每个图像添加链接,已经尝试在的每一侧放置标记 以下是脚本: <div id="content"> <img src="/images/main_banner01.jpg" border="0"> <img src="/images/main_banner02.jpg" border="0"> <img src="/images/main_bann
的每一侧放置
标记
以下是脚本:
<div id="content">
<img src="/images/main_banner01.jpg" border="0">
<img src="/images/main_banner02.jpg" border="0">
<img src="/images/main_banner03.jpg" border="0">
<img src="/images/main_banner04.jpg" border="0">
</div>
$(函数(){
var p=$(“#内容”)。响应幻灯片({
高度:484,//幻灯片内容器高度
背景:'#fff',//背景颜色和覆盖层的颜色在初始化时淡出
autoStart:true,//布尔值autoStart
startDelay:0,//延迟启动
effectInterval:5000,//交换照片的时间
effectTransition:1000,//时间效果
分页:[
{
active:true,//激活分页
内部:true,//内部分页或使用幻灯片内容器
位置:'B_L',/*
分页对齐:
T_L=左上角
T_C=上止点
T_R=右上角
B_L=左下角
B_C=底部中心
B_R=右下角
*/
边距:10,//分页边距
点样式:“”,//点分页类样式
dotStyleHover:“”,//点分页类悬停样式
dotStyleDisable:“”//点分页类禁用样式
}
]
});
});
以下是jquery:
<script language="javascript">
$(function(){
var p=$('#content').responsiveSlides({
height:484, // slides conteiner height
background:'#fff', // background color and color of overlayer to fadeout on init
autoStart:true, // boolean autostart
startDelay:0, // start whit delay
effectInterval:5000, // time to swap photo
effectTransition:1000, // time effect
pagination:[
{
active:true, // activate pagination
inner:true, // pagination inside or aouside slides conteiner
position:'B_L', /*
pagination align:
T_L = top left
T_C = top center
T_R = top right
B_L = bottom left
B_C = bottom center
B_R = bottom right
*/
margin:10, // pagination margin
dotStyle:'', // dot pagination class style
dotStyleHover:'', // dot pagination class hover style
dotStyleDisable:'' // dot pagination class disable style
}
]
});
});
</script>
(函数($){
$.fn.responsiveSlides=函数(选项){
var_this=这个;
var_int=null;
var im='!important';
变量设置=$.extend({
img:null,
高度:$(_this).height(),
背景:“#fff”,
正在加载类样式:“”,
自动启动:对,
开始时间:0,
有效间隔:5000,
有效转换:1000,
分页:[{活动:真,内部:真,位置:'B_C',边距:10,点样式:“”,点样式悬停:“”,点样式禁用:“”]
},选项);
_this.RS_Start=函数(){
_这个。RS_Stop();
_int=setInterval(函数(){
var n=$('.current',$('.tgtimg',_this)).next('img');
如果(n.length==0){
n=$('img:first',$('tgtimg',_this));
}
_这张.RS_ShowPhoto(n);
},设置。有效间隔);
};
_this.RS_Stop=function(){clearInterval(_int);_int=null;}
_this.RS\u ShowPhoto=函数(下一步){
$('.current',$('.tgtimg',_this)).fadeOut(settings.effectTransition);
next.fadeIn(settings.effectTransition,function()){
$('.current',$('.tgtimg',_this)).removeClass('current');
$(this.addClass('current');
var std=设置。分页[0]。点样式禁用;
如果(标准!=''){
$('.+std,$('.pagination',_this)).removeClass(std);
$('div:eq('+$(this.index()+'),$('.pagination',_this)).addClass(std);
}否则{
$('div',$('.pagination',_this)).css('opacity',1);
$('div:eq('+$(this.index()+'),$('.pagination',_this)).css('opacity',0.5);
}
如果(_int==null&&settings.autoStart){u this.RS_Start();}
});
};
//var overstyle='position:absolute'+im+';height:100%'+im+';width:100%'+im+';text align:center'+im+';line height:'+settings.height+'px'+im+';z-index:2'+im+';background:'+settings.background+im+';';
var overstyle='position:absolute;height:100%;width:100%;text align:center;lineheight:'+settings.height+'px;z-index:2;背景色:'+settings.background+';';
if(settings.loadingClassStyle==''){
overstyle+='font-family:Arial'+im+';';
if(settings.background.toLowerCase()='#fff'| | settings.background.toLowerCase()='#ffffff'){
超风格+='color:#000'+im+';
}否则{
超风格+='color:#fff'+im+';
}
}
var tgtstyle='position:absolute'+im+';height:'+settings.height+'px'+im+';width:100%'+im+';background:'+settings.background+im+';z-index:1'+im+';溢出:hidden'+im;
$(_this).height(settings.height).prepend('loading..);
if(settings.img==null | | settings.img==undefined | | | settings.img==undefined'){
$('img',_this).appendTo($('tgtim',_this));
$('img',$('tgtimg',_this))。每个(函数(i,e){
$(this.attr('style','position:absolute;z-index:1;top:0px;left:0px;height:'+settings.height+'px;display:'+((i==0)?'block':'none'))
如果(i==0){
$(this.addClass('current');
}
});
}否则{
$.each(settings.img,function)(即,e){
$('.tgtimg',_this).append('';
});
}
$('img',$('tgtimg',_this)).onImagesLoad(函数(){
//所有图像都已加载。我可以初始化吗
$(窗口)。调整大小(函数(){
$('img',$('tgtimg',_this))。每个(函数(i,e){
var l=-($(e).width()-$(_this).width())/2);
如果($(_this).width()>$(e).width()){
l=($(_this).width()-$(e).width())/2;
}
$(e).css('left',l+'px');
});
}).trigger('resize');
var p=设置。分页[0];
如果(p.active){
变量pos=(p.position.substring(0,1)='T')?'top:'+p.margin+'px;':'bottom:'+p.margin+'px;';
(function($){
$.fn.responsiveSlides = function(options){
var _this=this;
var _int=null;
var im=' !important';
var settings = $.extend({
img:null,
height:$(_this).height(),
background:'#fff',
loadingClassStyle:'',
autoStart:true,
startDelay:0,
effectInterval:5000,
effectTransition:1000,
pagination:[{active:true, inner:true, position:'B_C', margin:10, dotStyle:'', dotStyleHover:'', dotStyleDisable:''}]
},options);
_this.RS_Start=function(){
_this.RS_Stop();
_int=setInterval(function(){
var n=$('.current',$('.tgtimg',_this)).next('img');
if(n.length==0){
n=$('img:first',$('.tgtimg',_this));
}
_this.RS_ShowPhoto(n);
},settings.effectInterval);
};
_this.RS_Stop=function(){clearInterval(_int); _int=null;}
_this.RS_ShowPhoto=function(next){
$('.current',$('.tgtimg',_this)).fadeOut(settings.effectTransition);
next.fadeIn(settings.effectTransition,function(){
$('.current',$('.tgtimg',_this)).removeClass('current');
$(this).addClass('current');
var std=settings.pagination[0].dotStyleDisable;
if(std!=''){
$('.'+std,$('.pagination',_this)).removeClass(std);
$('div:eq('+$(this).index()+')',$('.pagination',_this)).addClass(std);
}else{
$('div',$('.pagination',_this)).css('opacity',1);
$('div:eq('+$(this).index()+')',$('.pagination',_this)).css('opacity',0.5);
}
if(_int==null&&settings.autoStart){_this.RS_Start();}
});
};
//var overstyle='position:absolute'+im+'; height:100%'+im+'; width:100%'+im+'; text-align:center'+im+'; line-height:'+settings.height+'px'+im+'; z-index:2'+im+'; background:'+settings.background+im+';';
var overstyle='position:absolute; height:100%; width:100%; text-align:center; line-height:'+settings.height+'px; z-index:2; background-color:'+settings.background+';';
if(settings.loadingClassStyle==''){
overstyle+='font-family:Arial'+im+'; ';
if(settings.background.toLowerCase()=='#fff'||settings.background.toLowerCase()=='#ffffff'){
overstyle+='color:#000'+im+';';
}else{
overstyle+='color:#fff'+im+';';
}
}
var tgtstyle='position:absolute'+im+'; height:'+settings.height+'px'+im+'; width:100%'+im+'; background:'+settings.background+im+'; z-index:1'+im+'; overflow:hidden'+im;
$(_this).height(settings.height).prepend('<div class="overslide '+settings.loadingClassStyle+'" style="'+overstyle+'">loading..</div><div class="tgtimg" style="'+tgtstyle+'"></div>');
if(settings.img==null || settings.img==undefined || settings.img=='undefined'){
$('img',_this).appendTo($('.tgtimg',_this));
$('img',$('.tgtimg',_this)).each(function(i,e){
$(this).attr('style','position:absolute; z-index:1; top:0px; left:0px; height:'+settings.height+'px; display:'+((i==0)?'block':'none'))
if(i==0){
$(this).addClass('current');
}
});
}else{
$.each(settings.img,function(i,e){
$('.tgtimg',_this).append('<img src="'+e+'" style="position:absolute; z-index:1; top:0px; left:0px; height:'+settings.height+'px; display:'+((i==0)?'block':'none')+'" class="'+((i==0)?'current':'')+'">');
});
}
$('img',$('.tgtimg',_this)).onImagesLoad(function(){
// every images are loaded. can i init
$(window).resize(function(){
$('img',$('.tgtimg',_this)).each(function(i,e){
var l=-(($(e).width()-$(_this).width())/2);
if($(_this).width()>$(e).width()){
l=($(_this).width()-$(e).width())/2;
}
$(e).css('left',l+'px');
});
}).trigger('resize');
var p=settings.pagination[0];
if(p.active){
var pos=(p.position.substring(0,1)=='T')?'top:'+p.margin+'px; ':'bottom:'+p.margin+'px; ';
pos+=(p.position.substring(2,3)=='L')?'left:'+p.margin+'px; ':(p.position.substring(2,3)=='R')?'right:'+p.margin+'px; ':'left:50%; ';
var elm='';
$('img',$('.tgtimg',_this)).each(function(i,e){elm+='<div'+((p.dotStyle=='')?' style="float:left; height:15px; width:15px; background:#fff; margin-left:2px; cursor:pointer"':' class="'+p.dotStyle+'"')+'></div>';});
$(_this).append('<div class="pagination" style="position:absolute; z-index:10; '+pos+'">'+elm+'</div>');
if(p.position.substring(2,3)=='C'){
$('.pagination',_this).css('margin-left','-'+parseInt($('.pagination',_this).width()/2)+'px');
}else if(p.position.substring(2,3)=='R'){
$('.pagination',_this).css('margin-left','-'+($('.pagination',_this).width()+p.margin)+'px');
}
if(!p.inner){
$('.pagination',_this).css('margin-top',-$('.pagination',_this).height()-(p.margin*2)+'px');
$('.pagination',_this).css('margin-bottom',-$('.pagination',_this).height()-(p.margin*2)+'px');
}
$('div',$('.pagination',_this)).mouseover(function(){
if(p.dotStyleHover!=''){$(this).addClass(p.dotStyleHover);}else{$(this).css('background','#CCC');}
}).mouseout(function(){
if(p.dotStyleHover!=''){$(this).removeClass(p.dotStyleHover);}else{$(this).css('background','#fff');}
}).click(function(){
_this.RS_Stop();
_this.RS_ShowPhoto($('img:eq('+$(this).index()+')',$('.tgtimg',_this)));
});
}
// init transition after delay and remove overlayer whit custom bg color
$('.overslide',_this).delay(settings.startDelay).fadeOut(settings.effectTransition,function(){
if(settings.autoStart){_this.RS_Start();}
$('div:eq(0)',$('.pagination',_this)).css('opacity',0.5);
});
});
return _this;
};
}(jQuery));
<div id="content">
<img data-href="/url1" src="/images/main_banner01.jpg" border="0">
<img data-href="/url2" src="/images/main_banner02.jpg" border="0">
<img data-href="/url3" src="/images/main_banner03.jpg" border="0">
<img data-href="/url4" src="/images/main_banner04.jpg" border="0">
</div>
$('#content img').click(function(){
window.location =$(this).attr('data-href');
});
<img src="/images/main_banner01.jpg" data-href='#' border="0">
$('#content img').click(function(){
window.location.href = $(this).data('href');
});