Как остановить слайд-шоу при наведении курсора мыши (слайд-шоу должно начинаться как обычно после отключения мыши) в сценарии Java

0

Привет, я потратил более 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> 
  • 0
    Можете ли вы создать jsfiddle ? Мы можем помочь вам лучше в этом.
  • 0
    @ShadowCat7: ShadowCat7: Спасибо за ваш ответ. Я получил некоторые ошибки. Посмотреть это jsfiddle.net/kiranlanke/JgEgL

2 ответа

0
Лучший ответ

Этот jsfiddle должен быть примером того, что вы ищете.

В вашем коде есть некоторые странные детали, такие как $("#slideshow")(function() { $(this).slides("play"); }); , это не имеет смысла. Я удалил их для своего примера.

Мой пример включает привязку наведения, используемую в ответе Йохан Ван ден Рим.

В основном, я добавил логическое значение, которое отслеживает, скользят ли слайды:

var isStopped = false; function slideSwitch() { if (!isStopped) {...

И в конце я добавил состояния зависания:

$("#slideshow").hover(function() { isStopped = true; }, function() { isStopped = false; });

0
$("#slideshow").hover(
  function() {
    $(this).slides("stop");
  }, 
  function() {
    $(this).slides("play");
});
  • 0
    Я попробовал это тоже, но безрезультатно. Может быть, я положил его в неправильном месте, если вы не мой, пожалуйста, сообщите мне место

Ещё вопросы

Сообщество Overcoder
Наверх
Меню