主要是下面这段话有问题,但是我想实现,鼠标放到图片上,图片就不动的效果
$(".imgbox").hover(
function(){ console.log("hover clearInterval+++index="+index+" pre="+pre);clearInterval(handid);},
function(){ console.log("hover setInterval+++index="+index+" pre="+pre);setInterval(self.Play , this.timer);});
$(".imgbox").hover(
function(){ console.log("hover clearInterval+++index="+index+" pre="+pre);clearInterval(handid);},
function(){ console.log("hover setInterval+++index="+index+" pre="+pre);setInterval(self.Play , this.timer);});
下载地址http://download.csdn.net/detail/slwsss/8137721
this.list = $(".imgbox").children(":first").children();
this.indexs = [];
this.length = this.list.length;
//图片显示时间
this.timer = 3000;
this.showTitle = $(".title"); var index = 0, self = this, pre = 0, handid, isPlay = false, isPagerClick = false; this.Start = function () {
this.Init();
//计时器,用于定时轮播图片
handid = setInterval(function(){self.Play()}, this.timer);////////////////////////////////// };
//初始化
this.Init = function () {
//////////////////////////////////
$(".imgbox").mouseenter(function () { clearInterval(handid); }).mouseleave(function () { handid = setInterval(function () { self.Play() }, self.timer); }); var o = $(".pager ul li"); for (var i = o.length - 1, n = 0; i >= 0; i--, n++) {
this.indexs[n] = o.eq(i).click(self.PagerClick);
}
};
this.Play = function () {
isPlay = true;
index++;
if (index == self.length) {//说明已经播放到了最后一个,从第一个重新开始播放
index = 0;
} console.log("Play+++index=" + index);
console.log("Play+++pre=" + pre);
//先淡出,在回调函数中执行下一张淡入
self.list.eq(pre).fadeOut(300, function () { self.imageIn() }); //end of fadeout
};
this.imageIn = function () {
var info = self.list.eq(index).fadeIn(500, function () {
isPlay = false;
//////////////////////////////////if (isPagerClick) { handid = setInterval(self.Play, self.timer); isPagerClick = false; }
}).attr("title"); //显示标题
self.showTitle.text(info);
//图片序号背景更换
self.indexs[index].css("background-color", "#FF70Ad");
self.indexs[pre].css("background-color", "#6f4f67");
pre = index;
console.log("imageIn+++pre=" + pre); }
//图片序号点击
this.PagerClick = function () {
if (isPlay) { return; }
isPagerClick = true; clearInterval(handid); var oPager = $(this), i = parseInt(oPager.text()) - 1; if (i != pre) {
index = i - 1;
}
self.Play();
};
};
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>s</title>
<style type="text/css">
ul,li{margin: 0;padding: 0;list-style: none}
#out_div{position:relative;border: 1px solid #ccc;width: 400px;height: 200px;margin: 200px auto}
.banner{height:200px;position: relative;overflow: hidden}
.banner li{position: absolute;width: 100%;left: 0;background-repeat: repeat-x;background-position: center}
.banner img{width:400px;height: 200px;z-index:1;}
.banner_li{position: absolute;left:50%;margin-top: -20px;}
.banner_li li{font-size:0;float: left;width:12px;height:12px;margin-left:7px;cursor: pointer;border-radius: 50%;background-color:#ddd;cursor: pointer}
.banner_li .on_li{background-color:#f30}
</style>
</head>
<body>
<div id="out_div">
<ul class="banner">
<li><a href="javascript:void(0)"><img src="http://down.scscms.com/scs/pic/1.jpg" alt=""/></a></li>
<li><a href="javascript:void(0)"><img src="http://down.scscms.com/scs/pic/2.jpg" alt=""/></a></li>
<li><a href="javascript:void(0)"><img src="http://down.scscms.com/scs/pic/3.jpg" alt=""/></a></li>
<li><a href="javascript:void(0)"><img src="http://down.scscms.com/scs/pic/4.jpg" alt=""/></a></li>
</ul>
</div>
<script type="text/javascript" src="http://down.scscms.com/scs/pic/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(function(){
function animate(){
i ++;old = li.filter(":visible");
if(i != old.index()){
i >= l && (i = 0);
$(".banner_li li").removeAttr("class").eq(i).addClass("on_li");
li.eq(i).css({zIndex:1,display:"block",opacity:0}).animate({opacity:1},1000,function(){$(this).css({zIndex:0});old.hide()})
}
}
var li = $(".banner li"),l = li.size(),i = 0,arr = new Array(l);
$(".banner").after('<ul class="banner_li" style="z-index:2;margin-left: -'+Math.floor(l/2*13)+'px"><li class="on_li">'+arr.join("</li><li>")+'</li></ul>');
var old = li.first().show(),fun = setInterval(animate,6000);
$(".banner_li").delegate("li","click",function(){i = $(this).index()-1;animate()}).hover(function(){clearInterval(fun)},function(){fun = setInterval(animate,6000)});
})
</script>
</body>
</html>
function(){ console.log("hover clearInterval+++index="+index+" pre="+pre);clearInterval(handid);},
function(){ console.log("hover setInterval+++index="+index+" pre="+pre);setInterval(self.Play , this.timer);});红色的this指向.imgbox这个对象,已经不是你的实例对象,导致为0就会一直变换,而且你也没有记录setInterval这个计时器。。导致无法清除计时器setInterval(self.Play , this.timer)你这样写会导致Play执行后this对象指向window,不在是示例,不过你的play用的是self对象,这样写也是可以的,但是不能再play里面用this对象,this==window,所以用写成我那种形式
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jQuery焦点幻灯片特效 在线演示 DIVCSS5</title><style type="text/css">
* {margin:0; padding:0;}
body {font-size:12px; color:#222; font-family:Verdana,Arial,Helvetica,sans-serif; background:#f0f0f0;}
.clearfix:after {content: "."; display: block; height: 0; clear: both; visibility: hidden;}
.clearfix {zoom:1;}
ul,li {list-style:none;}
img {border:0;}
h1 {height:50px; line-height:50px; font-size:22px; font-weight:normal; font-family:"Microsoft YaHei",SimHei;}
/* focus */
#focus {width:100%; height:280px; overflow:hidden; position:relative;}
#focus ul {height:380px; position:absolute;}
#focus ul li {float:left; width:100%; height:280px; overflow:hidden; position:relative; background:#000;}
#focus ul li div {position:absolute; overflow:hidden;}
#focus .btnBg {position:absolute; width:100%; height:20px; left:0; bottom:0; background:#000;}
#focus .btn {position:absolute; width:700px; height:10px; padding:5px 10px; right:0; bottom:0; text-align:right;}
#focus .btn span {display:inline-block; _display:inline; _zoom:1; width:25px; height:10px; _font-size:0; margin-left:5px; cursor:pointer; background:#fff;}
#focus .btn span.on {background:#fff;}
#focus .preNext {width:45px; height:100px; position:absolute; top:90px; background:url(img/sprite.png) no-repeat 0 0; cursor:pointer;}
#focus .pre {left:0;}
#focus .next {right:0; background-position:right top;}#n{margin:10px auto; width:920px; border:1px solid #CCC;font-size:12px; line-height:30px;}
#n a{ padding:0 4px; color:#333}
</style><script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var sWidth = $("#focus").width(); //获取焦点图的宽度(显示面积)
var len = $("#focus ul li").length; //获取焦点图个数
var index = 0;
var picTimer;
//以下代码添加数字按钮和按钮后的半透明条,还有上一页、下一页两个按钮
var btn = "<div class='btnBg'></div><div class='btn'>";
for(var i=0; i < len; i++) {
btn += "<span></span>";
}
btn += "</div><div class='preNext pre'></div><div class='preNext next'></div>";
$("#focus").append(btn);
$("#focus .btnBg").css("opacity",0.5); //为小按钮添加鼠标滑入事件,以显示相应的内容
$("#focus .btn span").css("opacity",0.4).mouseenter(function() {
index = $("#focus .btn span").index(this);
showPics(index);
}).eq(0).trigger("mouseenter"); //上一页、下一页按钮透明度处理
$("#focus .preNext").css("opacity",0.2).hover(function() {
$(this).stop(true,false).animate({"opacity":"0.5"},300);
},function() {
$(this).stop(true,false).animate({"opacity":"0.2"},300);
}); //上一页按钮
$("#focus .pre").click(function() {
index -= 1;
if(index == -1) {index = len - 1;}
showPics(index);
}); //下一页按钮
$("#focus .next").click(function() {
index += 1;
if(index == len) {index = 0;}
showPics(index);
}); //本例为左右滚动,即所有li元素都是在同一排向左浮动,所以这里需要计算出外围ul元素的宽度
$("#focus ul").css("width",sWidth * (len));
//鼠标滑上焦点图时停止自动播放,滑出时开始自动播放
$("#focus").hover(function() {
clearInterval(picTimer);
},function() {
picTimer = setInterval(function() {
showPics(index);
index++;
if(index == len) {index = 0;}
},4000); //此4000代表自动播放的间隔,单位:毫秒
}).trigger("mouseleave");
//显示图片函数,根据接收的index值显示相应的内容
function showPics(index) { //普通切换
var nowLeft = -index*sWidth; //根据index值计算ul元素的left值
$("#focus ul").stop(true,false).animate({"left":nowLeft},300); //通过animate()调整ul元素滚动到计算出的position
//$("#focus .btn span").removeClass("on").eq(index).addClass("on"); //为当前的按钮切换到选中的效果
$("#focus .btn span").stop(true,false).animate({"opacity":"0.4"},300).eq(index).stop(true,false).animate({"opacity":"1"},300); //为当前的按钮切换到选中的效果
}
});</script>
</head><body>
<p id="n"><a href="http://www.divcss5.com/">CSS</a>
<a href="http://www.divcss5.com/">divcss5</a>:
<a href="http://www.divcss5.com/html/">Html基础</a>
<a href="http://www.divcss5.com/htmlrumen/">html入门</a>
<a href="http://www.divcss5.com/rumen/">CSS基础</a>
<a href="http://www.divcss5.com/cssrumen/">CSS入门</a>
<a href="http://www.divcss5.com/css-hack/">CSS Hack</a>
<a href="http://www.divcss5.com/css-texiao/">CSS特效</a>
<a href="http://www.divcss5.com/template/">CSS模块</a>
<a href="http://www.divcss5.com/wenji/">CSS知答</a>
<a href="http://www.divcss5.com/peixun/">CSS培训</a>
<a href="http://www.css5.com.cn/">CSS切图</a>
<a href="http://www.divcss5.com/css-tool/">CSS工具</a>
<a href="http://www.divcss5.com/jiqiao/">CSS技巧</a>
<a href="http://www.divcss5.com/">DIV+CSS</a></p>
<p> </p>
<div class="wrapper">
<h1>jQuery+DIV+CSS焦点幻灯片特效效果如下:</h1> <div id="focus">
<ul>
<li><a href="http://www.divcss5.com/" target="_blank"><img src="img/01.jpg" alt="CSS" /></a></li>
<li><a href="http://www.divcss5.com/" target="_blank"><img src="img/02.jpg" alt="DIV CSS" /></a></li>
<li><a href="http://www.divcss5.com/" target="_blank"><img src="img/03.jpg" alt="DIV+CSS" /></a></li>
<li><a href="http://www.divcss5.com/html/" target="_blank"><img src="img/04.jpg" alt="HTML" /></a></li>
<li><a href="#" target="_blank"><img src="img/05.jpg" alt="jquery商城焦点图展示" /></a></li>
</ul>
</div>
</div>
<p> </p>
<p>返回下载 <a href="http://www.divcss5.com/css-texiao/texiao637.shtml">JQ+CSS幻灯片特效</a>:<a href="http://www.divcss5.com/css-texiao/texiao637.shtml">http://www.divcss5.com/css-texiao/texiao637.shtml</a></p>
</body>
</html>
以上的代码,是一个全屏可以滚动播放的代码,但是只能播放第一张,不知道是为什么,着急死了,不知道是哪里出错了,请帮我看一下,具体错误就是以为内foucs的div的width为100%,如果不为100%,就可以正常。