Javascript 如何在java脚本中停止鼠标悬停的幻灯片放映(幻灯片放映应在鼠标悬停后照常开始)
嗨,我花了10多个小时来停止滑鼠上的幻灯片放映,开始滑鼠下。我在stack overflow中看到一些建议,我没有得到任何解决方案(可能是我的错误,根据我的代码理解了其他代码。因此,我给出了我的代码) 代码是:Javascript 如何在java脚本中停止鼠标悬停的幻灯片放映(幻灯片放映应在鼠标悬停后照常开始),javascript,jquery,html,css,Javascript,Jquery,Html,Css,嗨,我花了10多个小时来停止滑鼠上的幻灯片放映,开始滑鼠下。我在stack overflow中看到一些建议,我没有得到任何解决方案(可能是我的错误,根据我的代码理解了其他代码。因此,我给出了我的代码) 代码是: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="
<!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 content="text/html; charset=iso-8859-1" http-equiv="Content-Type"/>
<title>Simple jQuery Slideshow from JonRaasch.com</title>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript">
/***
Simple jQuery Slideshow Script
Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc. Please link out to me if you like it :)
***/
function slideSwitch() {
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
// use this to pull the images in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
// uncomment the 3 lines below to pull the images in random order
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 1500 );
});
$("#slideshow")(function() { $(this).slides("stop"); });
//playing all slides
$("#slideshow")(function() { $(this).slides("play"); });
</script>
<style type="text/css">
/*** set the width and height to match your images **/
#slideshow {
position:relative;
height:350px;
width: 40%;
}
#slideshow IMG {
position:absolute;
top:0;
left:0;
z-index:8;
opacity:0.0;
}
#slideshow IMG.active {
z-index:10;
opacity:1.0;
}
#slideshow IMG.last-active {
z-index:9;
}
</style>
</head>
<body style="font-family: Arial, Sans-serif, sans;">
<!-- this will work with any number of images -->
<!-- set the active class on whichever image you want to show up as the default
(otherwise this will be the last image) -->
<div id="slideshow">
<img src="image1.jpg" alt="Slideshow Image 1" class="active" />
<img src="image2.jpg" alt="Slideshow Image 2" />
<img src="image3.jpg" alt="Slideshow Image 3" />
<img src="image4.jpg" alt="Slideshow Image 4" />
</div>
</body>
</html>
来自JonRaasch.com的简单jQuery幻灯片
/***
简单jQuery幻灯片脚本
由Jon Raasch(jonraasch.com)根据FreeBSD许可证发布:免费使用或修改,不对任何内容负责等。如果您喜欢,请链接到我:)
***/
函数滑动开关(){
var$active=$(“#slideshow IMG.active”);
如果($active.length==0)$active=$(“#幻灯片显示IMG:last”);
//使用此选项可以按图像在标记中的显示顺序提取图像
var$next=$active.next().length?$active.next()
:$(“#幻灯片演示IMG:first”);
//取消对下面3行的注释,以随机顺序拖动图像
//var$sibs=$active.sibles();
//var rndNum=Math.floor(Math.random()*$sibs.length);
//var$next=$($sibs[rndNum]);
$active.addClass('last-active');
$next.css({opacity:0.0})
.addClass(“活动”)
.animate({opacity:1.0},1000,function()){
$active.removeClass('active last active');
});
}
$(函数(){
设置间隔(“滑动开关()”,1500);
});
$(“#slideshow”)(function(){$(this.slides(“stop”);});
//播放所有幻灯片
$(“#slideshow”)(function(){$(this.slides(“play”);});
/***设置宽度和高度以匹配图像**/
#幻灯片放映{
位置:相对位置;
高度:350px;
宽度:40%;
}
#幻灯片式IMG{
位置:绝对位置;
排名:0;
左:0;
z指数:8;
不透明度:0.0;
}
#幻灯片显示IMG.active{
z指数:10;
不透明度:1.0;
}
#幻灯片显示IMG.last-active{
z指数:9;
}
应该是您正在寻找的示例
代码中有一些奇怪的部分,例如$(“#slideshow”)(function(){$(this.slides(“play”);})代码>,这毫无意义。我删除了这些作为我的例子
我的例子包括johanvandenrym的答案中使用的悬停绑定
基本上,我添加了一个布尔值,用于跟踪幻灯片是否悬停:
var=false;
函数滑动开关(){
如果(!isStopped){
…
最后我添加了悬停状态:
$(“#幻灯片”)。悬停(函数(){
isStopped=true;
},函数(){
isStopped=false;
});
你能创建一个吗?我们可以通过这种方式帮助你更好。@ShadowCat7:谢谢你的回复。我有一些错误。看到了吗?我也尝试了,但没有结果。如果你没有我的,我可能放错地方了。请告诉我位置
$("#slideshow").hover(
function() {
$(this).slides("stop");
},
function() {
$(this).slides("play");
});