如何停止幻灯片显示在鼠标上(幻灯片显示应该像往常一样开始后鼠标退出)在java脚本
How stop slide show on mouse over (slide show should start as usual after mouse out) in java script
嗨,我花了10多个小时来停止鼠标上方的幻灯片播放,并开始鼠标移出。我在堆栈溢出中看到了一些建议,我没有得到任何解决方案(可能这是我的错误,根据我的代码来理解其他人的代码。因此,我给我的代码)。
代码是:
<!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>
这个jsfiddle应该是你正在寻找的一个例子。
你的代码中有一些奇怪的部分,比如$("#slideshow")(function() { $(this).slides("play"); });
,没有意义。我删除了我的例子。
我的例子包括在Johan Van den Rym的回答中使用的悬停绑定。
基本上,我添加了一个布尔值来跟踪幻灯片是否被悬停:
var isStopped = false; function slideSwitch() { if (!isStopped) { ...
最后我添加了悬停状态
$("#slideshow").hover(function () { isStopped = true; }, function () { isStopped = false; });
$("#slideshow").hover(
function() {
$(this).slides("stop");
},
function() {
$(this).slides("play");
});
相关文章:
- 如何在MVC3中显示鼠标悬停在文本上的部分视图
- 如何在asp:linkButton上显示鼠标悬停事件上的图像
- 引导程序手风琴显示鼠标悬停上的数据
- 谷歌可视化时间线显示鼠标光标的时间
- 在图像附近显示鼠标上的工具提示
- 在phantom.js中显示鼠标光标
- 在谷歌地图v3中显示鼠标悬停事件的工具提示
- 使用jQuery显示鼠标悬停在列表元素上时的高亮效果
- JavaScript显示鼠标多次单击的坐标
- 如何使用Javascript隐藏和显示鼠标悬停在包含元素上的元素
- 显示鼠标位置
- 如何使用JS和CSS在html中显示鼠标弹出窗口
- 我想为选中的项目附加一个点击事件,并在jquery的自动完成控件中显示鼠标上的工具提示
- 如何显示鼠标悬停标题单元格的工具提示?
- UI滑块显示鼠标上移前后移动值的差异
- 高亮显示鼠标在某个范围内的位置
- 如何在php中显示鼠标悬停时弹出的文本
- jQuery显示鼠标离开后隐藏延迟仍在运行
- 如何在fabric.js中显示鼠标坐标?
- 使用JavaScript显示鼠标性别和鼠标位置不起作用