JQury自动切换图片----带有小图片,代码一共不超过100行
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JQury自动切换图片----带有小图片,代码一共不超过100行相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="" />
<style type="text/css">
#img1{
width: 500px;
height: 400px;
}
.titldiv img{
width: 50px;
height: 50px;
}
#titlimg1{
width: 60px;
height: 60px;
}
</style>
<script type="text/javascript">
window.onload=init;
var i=0;//小图片
var n=1; //图片标记数
var dingshi; //让图片动的定时器
function init(){
dingshi=window.setInterval("tupian()",1000);
}
//更换图片
function tupian(){
var obj=document.getElementById("img1");
var titlpic=document.querySelectorAll(".titldiv img");
for(var j=0;j<titlpic.length;j++){
titlpic[j].setAttribute("style","width: 50px;height: 50px;");
}
i++;//小图片切换
n++;
if(n>4){
n=1;
}
if(i>=4){
i=0;
}
obj.src="img/yaj_"+n+".png";
titlpic[i].setAttribute("style","width: 60px;height: 60px;");
}
//鼠标放上图片停止
function stoptupian(){
window.clearInterval(dingshi);
}
//鼠标离开图片动起来
function dongqilai(){
dingshi=window.setInterval("tupian()",1000);
}
//当鼠标移到小图片时
function stoptimg(a){
n=a;
i=a-1;
var obj=document.getElementById("img1");
obj.src="img/yaj_"+n+".png";
var titlpic=document.querySelectorAll(".titldiv img");
for(var j=0;j<titlpic.length;j++){
titlpic[j].setAttribute("style","width: 50px;height: 50px;");
}
titlpic[i].setAttribute("style","width: 60px;height: 60px;");
window.clearInterval(dingshi);
}
</script>
</head>
<body>
<img src="img/yaj_1.png" onmouseover="stoptupian()" onmouseout="dongqilai()" id="img1">
<div class="titldiv">
<img src="img/yaj_1.png" class="titl" id="titlimg1" onmouseover="stoptimg(1)" onmouseout="dongqilai()"/>
<img src="img/yaj_2.png" onmouseover="stoptimg(2)" onmouseout="dongqilai()"/>
<img src="img/yaj_3.png" onmouseover="stoptimg(3)" onmouseout="dongqilai()""/>
<img src="img/yaj_4.png" onmouseover="stoptimg(4)" onmouseout="dongqilai()"/>
</div>
</body>
</html>
以上是关于JQury自动切换图片----带有小图片,代码一共不超过100行的主要内容,如果未能解决你的问题,请参考以下文章