jquery 图片轮换效果
更新时间:2010年07月29日 12:21:11 作者:
重写了昨天的图片轮换,加入了自动切换效果,改变了布局,增强了可定制性,当然,还是有点小小的问题,在IE 6+,chrome,firfox3.68下测试正常运行
效果图:
代码中存在的错误欢迎大家指正
/**
* @author leepood
* @title 图片自动轮换效果
* @version v2.0
* @E-Mail leepood@gmail.com
* @notice:要显示图片的数目可以在setting里调整,但需要在imagesArray中加入相应图片的参数
*/
function changeImages()
{
var setting={
'width':'330px',
'height':'200px',
'images_count':'4',
'time':'1800', //图片切换的速度
'imageschange_border_color':'#fcf0a1'
};
var imagesArray=[{'src':'images/1.bmp','href':'http://www.baidu.com/','title':'秋天,一片金色','target':'_blank'},
{'src':'images/2.bmp','href':'http://www.163.com','title':'春天,给人一片生机的感觉','target':'_blank'},
{'src':'images/3.bmp','href':'http://iagyje.blog.163.com','title':'龙眼最好吃了,我每次吃好多的','target':'_blank'},
{'src':'images/4.bmp','href':'http://www.sina.com/','title':'火红的枫叶啊,有机会看看去','target':'_blank'}];
//添加元素,定义变量
var $div_imageschange=$("#imageschange");
$div_imageschange.children().css("margin","0px").css("padding","0px");
$div_imageschange.append("<div id='images_button'></div>");
$div_imageschange.append("<div id='images_title'></div>");
var $div_images_title=$("#images_title");
var $div_images_button=$("#images_button");
var count=setting.images_count;
for(var a=0;a<count;a++)
{
var b=a+1;
$div_images_button.append("<a id='"+b+"'>"+b+"</a>");
}
var $link_buttons=$("#imageschange a");
//设置元素的初始属性
//最外层容器,容纳所有元素
$div_imageschange.css("width",setting.width)
.css("position","relative")
.css("height",setting.height)
.css("border","solid 1px "+setting.imageschange_border_color);
//容纳按钮的元素
$div_images_button.css("position","absolute")
.css("height","20px")
.css("right","0px")
.css("bottom","21px")
.css("opacity","1")
.css("float","right");
//容纳文字说明的元素
$div_images_title.css("position","absolute")
.css("height","20px")
.css("width",setting.width)
.css("bottom","0px")
.css("right","0px")
.css("background-color","black")
.css("opacity","0.6")
.css("font-size","12px")
.css("color","white");
//按钮组合
$link_buttons.css("width","15px")
.css("height","15px")
.css("border","solid 1px #fcf0a1")
.css("display","block")
.css("margin","0 5px 5px 5px")
.css("font-size","12px")
.css("text-align","center")
.css("float","left")
.css("color","white")
.css("text-decoration","none");
//初始化设定
$div_imageschange.css("background-image","url('images/1.bmp')");
$div_images_title.html(imagesArray[0].title);
$("#images_button a:first").css("background","#fcf0a1");
function change(index){
$div_imageschange.css("background-image", "none");
$div_imageschange.css("background-image", "url('" + imagesArray[index].src + "')");
$div_images_title.html("");
$div_images_title.html(imagesArray[index].title);
$($link_buttons[index]).attr("href", imagesArray[index].href).attr("target", imagesArray[index].target);
$link_buttons.css("background","");
$($link_buttons[index]).css("background","#fcf0a1");
};
//自动切换代码
function autochange(){
var i=0;
setInterval(function(){
change(i);
if(i==setting.images_count-1)
{
i=-1;
}
i++;
},setting.time);
}
autochange();
//手动切换代码
$link_buttons.each(function(i){
$(this).hover(function(){
change(i);
});
});
};
$(document).ready(function(){
changeImages();
});
要显示图片的数目可以在setting里调整,但需要在imagesArray中加入相应图片的参数
代码中存在的错误欢迎大家指正
复制代码 代码如下:
/**
* @author leepood
* @title 图片自动轮换效果
* @version v2.0
* @E-Mail leepood@gmail.com
* @notice:要显示图片的数目可以在setting里调整,但需要在imagesArray中加入相应图片的参数
*/
function changeImages()
{
var setting={
'width':'330px',
'height':'200px',
'images_count':'4',
'time':'1800', //图片切换的速度
'imageschange_border_color':'#fcf0a1'
};
var imagesArray=[{'src':'images/1.bmp','href':'http://www.baidu.com/','title':'秋天,一片金色','target':'_blank'},
{'src':'images/2.bmp','href':'http://www.163.com','title':'春天,给人一片生机的感觉','target':'_blank'},
{'src':'images/3.bmp','href':'http://iagyje.blog.163.com','title':'龙眼最好吃了,我每次吃好多的','target':'_blank'},
{'src':'images/4.bmp','href':'http://www.sina.com/','title':'火红的枫叶啊,有机会看看去','target':'_blank'}];
//添加元素,定义变量
var $div_imageschange=$("#imageschange");
$div_imageschange.children().css("margin","0px").css("padding","0px");
$div_imageschange.append("<div id='images_button'></div>");
$div_imageschange.append("<div id='images_title'></div>");
var $div_images_title=$("#images_title");
var $div_images_button=$("#images_button");
var count=setting.images_count;
for(var a=0;a<count;a++)
{
var b=a+1;
$div_images_button.append("<a id='"+b+"'>"+b+"</a>");
}
var $link_buttons=$("#imageschange a");
//设置元素的初始属性
//最外层容器,容纳所有元素
$div_imageschange.css("width",setting.width)
.css("position","relative")
.css("height",setting.height)
.css("border","solid 1px "+setting.imageschange_border_color);
//容纳按钮的元素
$div_images_button.css("position","absolute")
.css("height","20px")
.css("right","0px")
.css("bottom","21px")
.css("opacity","1")
.css("float","right");
//容纳文字说明的元素
$div_images_title.css("position","absolute")
.css("height","20px")
.css("width",setting.width)
.css("bottom","0px")
.css("right","0px")
.css("background-color","black")
.css("opacity","0.6")
.css("font-size","12px")
.css("color","white");
//按钮组合
$link_buttons.css("width","15px")
.css("height","15px")
.css("border","solid 1px #fcf0a1")
.css("display","block")
.css("margin","0 5px 5px 5px")
.css("font-size","12px")
.css("text-align","center")
.css("float","left")
.css("color","white")
.css("text-decoration","none");
//初始化设定
$div_imageschange.css("background-image","url('images/1.bmp')");
$div_images_title.html(imagesArray[0].title);
$("#images_button a:first").css("background","#fcf0a1");
function change(index){
$div_imageschange.css("background-image", "none");
$div_imageschange.css("background-image", "url('" + imagesArray[index].src + "')");
$div_images_title.html("");
$div_images_title.html(imagesArray[index].title);
$($link_buttons[index]).attr("href", imagesArray[index].href).attr("target", imagesArray[index].target);
$link_buttons.css("background","");
$($link_buttons[index]).css("background","#fcf0a1");
};
//自动切换代码
function autochange(){
var i=0;
setInterval(function(){
change(i);
if(i==setting.images_count-1)
{
i=-1;
}
i++;
},setting.time);
}
autochange();
//手动切换代码
$link_buttons.each(function(i){
$(this).hover(function(){
change(i);
});
});
};
$(document).ready(function(){
changeImages();
});
要显示图片的数目可以在setting里调整,但需要在imagesArray中加入相应图片的参数
相关文章
Jquery遍历select option和添加移除option的实现方法
下面小编就为大家带来一篇Jquery遍历select option和添加移除option的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2016-08-08jQuery实现分页功能(含ajax请求、后台数据、附完整demo)
这篇文章主要给大家介绍了关于jQuery实现分页功能的相关资料,主要包含ajax请求和后台数据,文末给出了完整的demo示例,对大家具有一定的参考价值,需要的朋友们下面来一起看看吧。2017-04-04jQuery实现Table表格隔行变色及高亮显示当前选择行效果示例
这篇文章主要介绍了jQuery实现Table表格隔行变色及高亮显示当前选择行效果,涉及jQuery针对table元素遍历、运算、样式及鼠标事件动态响应相关操作技巧,需要的朋友可以参考下2017-02-02
最新评论