js调用jQuery实现点击左右按钮切换图片 5
下面的代码,点击左右按钮切换没反应怎么回事啊?<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http:...
下面的代码,点击左右按钮切换没反应怎么回事啊?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{padding:0;margin:0;}
body{background:#999;}
ul,li{list-style:none;}
img{border:none;vertical-align:middle;}
#ul1{width:210px;height:315px;border:1px solid red;margin:auto;position:relative;}
#ul1 li{position:absolute;}
#ul2{width:420px;height:105px;margin:auto;}
#ul2 li{float:left;}
#ul2 li img{width:70px;height:105px;opacity:0.5;}
#left_a{position:absolute;width:105px;height:315px;top:0;left:0;background:red;filter:alpha(opacity:0);opacity:0;z-index:1000;}
#right_a{position:absolute;width:105px;height:315px;top:0;left:105px;background:green;filter:alpha(opacity:0);opacity:0;z-index:1000;}
#left_p{position:absolute;z-index:1002;left:5px;top:130px;filter:alpha(opacity:0);opacity:0;}
#left_p:hover{cursor:pointer;}
#right_p:hover{cursor:pointer;}
#right_p{position:absolute;z-index:1002;right:5px;top:130px;filter:alpha(opacity:0);opacity:0;}
#mov2{overflow:hidden;width:210px;margin:auto;}
</style>
<script src="js/move.js"></script>
<script src="js/jquery-2.1.1.min.js"></script>
<script>
window.onload=function(){
var leftA=document.getElementById('left_a');
var rightA=document.getElementById('right_a');
var leftP=document.getElementById('left_p');
var rightP=document.getElementById('right_p');
leftP.onmouseover=leftA.onmouseover=function(){
startMove(leftP,'opacity',100);
}
leftP.onmouseoout=leftA.onmouseout=function(){
startMove(leftP,'opacity',0);
}
rightP.onmouseover=rightA.onmouseover=function(){
startMove(rightP,'opacity',100);
}
rightP.onmouseout=rightA.onmouseout=function(){
startMove(rightP,'opacity',0);
}
//点击箭头,图片切换
var znow=6;
var zdex=0;
var n=$('ul').children('li').length-1;
$('#left_p').click(function(){
zdex++;
znow++;
if(zdex>n){zdex==0;}
$('ul').children('li').eq(zdex).css('z-index','znow');
});
$('#right_p').click(function(){
zdex--;
znow++;
if(zdex<0){zdex==n;}
$('ul').children('li').eq(zdex).css('z-index','znow');
});
}
</script>
</head>
<body>
<ul id="ul1">
<img id='left_p' src="image/left.png" />
<img id='right_p' src="image/right.png" />
<li style="z-index:1;"><img src="image/1.jpg" /></li>
<li style="z-index:2;"><img src="image/2.jpg" /></li>
<li style="z-index:3;"><img src="image/3.jpg" /></li>
<li style="z-index:4;"><img src="image/4.jpg" /></li>
<li style="z-index:5;"><img src="image/5.jpg" /></li>
<li style="z-index:6;"><img src="image/6.jpg" /></li>
<a href="javascript:;" id="left_a"></a>
<a href="javascript:;" id="right_a"></a>
</ul>
</body>
</html>
function startMove(obj,attr,iTarget,fnEnd)
{
clearInterval(obj.timer);
obj.timer=setInterval(function()
{
var cur=0;
if(attr=='opacity')
{
cur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else
{
cur=parseInt(getStyle(obj,attr));
}
var speed=(iTarget-cur)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur==iTarget)
{
clearInterval(obj.timer);
if(fnEnd)aaa
fnEnd();
}
else
这段代码是startMove外链函数的第二部分(百度提问字数限制,只能分开写了) 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{padding:0;margin:0;}
body{background:#999;}
ul,li{list-style:none;}
img{border:none;vertical-align:middle;}
#ul1{width:210px;height:315px;border:1px solid red;margin:auto;position:relative;}
#ul1 li{position:absolute;}
#ul2{width:420px;height:105px;margin:auto;}
#ul2 li{float:left;}
#ul2 li img{width:70px;height:105px;opacity:0.5;}
#left_a{position:absolute;width:105px;height:315px;top:0;left:0;background:red;filter:alpha(opacity:0);opacity:0;z-index:1000;}
#right_a{position:absolute;width:105px;height:315px;top:0;left:105px;background:green;filter:alpha(opacity:0);opacity:0;z-index:1000;}
#left_p{position:absolute;z-index:1002;left:5px;top:130px;filter:alpha(opacity:0);opacity:0;}
#left_p:hover{cursor:pointer;}
#right_p:hover{cursor:pointer;}
#right_p{position:absolute;z-index:1002;right:5px;top:130px;filter:alpha(opacity:0);opacity:0;}
#mov2{overflow:hidden;width:210px;margin:auto;}
</style>
<script src="js/move.js"></script>
<script src="js/jquery-2.1.1.min.js"></script>
<script>
window.onload=function(){
var leftA=document.getElementById('left_a');
var rightA=document.getElementById('right_a');
var leftP=document.getElementById('left_p');
var rightP=document.getElementById('right_p');
leftP.onmouseover=leftA.onmouseover=function(){
startMove(leftP,'opacity',100);
}
leftP.onmouseoout=leftA.onmouseout=function(){
startMove(leftP,'opacity',0);
}
rightP.onmouseover=rightA.onmouseover=function(){
startMove(rightP,'opacity',100);
}
rightP.onmouseout=rightA.onmouseout=function(){
startMove(rightP,'opacity',0);
}
//点击箭头,图片切换
var znow=6;
var zdex=0;
var n=$('ul').children('li').length-1;
$('#left_p').click(function(){
zdex++;
znow++;
if(zdex>n){zdex==0;}
$('ul').children('li').eq(zdex).css('z-index','znow');
});
$('#right_p').click(function(){
zdex--;
znow++;
if(zdex<0){zdex==n;}
$('ul').children('li').eq(zdex).css('z-index','znow');
});
}
</script>
</head>
<body>
<ul id="ul1">
<img id='left_p' src="image/left.png" />
<img id='right_p' src="image/right.png" />
<li style="z-index:1;"><img src="image/1.jpg" /></li>
<li style="z-index:2;"><img src="image/2.jpg" /></li>
<li style="z-index:3;"><img src="image/3.jpg" /></li>
<li style="z-index:4;"><img src="image/4.jpg" /></li>
<li style="z-index:5;"><img src="image/5.jpg" /></li>
<li style="z-index:6;"><img src="image/6.jpg" /></li>
<a href="javascript:;" id="left_a"></a>
<a href="javascript:;" id="right_a"></a>
</ul>
</body>
</html>
function startMove(obj,attr,iTarget,fnEnd)
{
clearInterval(obj.timer);
obj.timer=setInterval(function()
{
var cur=0;
if(attr=='opacity')
{
cur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else
{
cur=parseInt(getStyle(obj,attr));
}
var speed=(iTarget-cur)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur==iTarget)
{
clearInterval(obj.timer);
if(fnEnd)aaa
fnEnd();
}
else
这段代码是startMove外链函数的第二部分(百度提问字数限制,只能分开写了) 展开
2个回答
展开全部
个人推荐还是用别人的插件吧。自己写的代码很多,而且不成熟,真正放项目里面可能会出现BUG
去百度arale,进官网,找switchable
去百度arale,进官网,找switchable
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
startMove(rightP,'opacity',0); 这个方法定义在哪里啦?
追问
function getStyle(obj,name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
}
else
{
return getComputedStyle(obj,false)[name];
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询