嗨,我花了10多個小時到超過鼠標停止幻燈片放映和鼠標開始了。我看到一些堆棧溢出的建議,我沒有得到任何解決方案(可能這是我的錯,根據我的代碼瞭解其他代碼,因此我正在給我的代碼)。如何在鼠標懸停時停止放映幻燈片(幻燈片應啓動鼠標移出後,像往常一樣)在Java腳本
代碼是:
<!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](http://jsfiddle.net/)嗎?我們可以以這種方式更好地幫助你。 – ShadowCat7
@ ShadowCat7:謝謝您的回覆。我有一些錯誤。看到這個http://jsfiddle.net/kiranlanke/JgEgL/ –