0

私はこのコードを持っています:

$(function () {
var current = 0,
$imgs = jQuery('#m_slider .ms1');
imgAmount = $imgs.length;

$($imgs.css('position', 'absolute').hide().get(0)).show();


window.setInterval(swapImages, 5000);

function swapImages() {

var $currentImg = $('.ms1:visible');

var $nextImg = $('.ms1:hidden').eq(Math.floor(Math.random() *$('.ms1:hidden').length));
    speed = 500;
// animation speed should be the same for both images so we have a smooth change
$currentImg.fadeOut(speed);
$nextImg.fadeIn(speed);
}
});

これはうまく機能しています。ホバー時にスライドショーを一時停止したいです。そのための .hover() 関数をどこに追加しますか???

4

1 に答える 1

0

これを試すことができます(テストされていません):

$(function () {
var current = 0, timer,
    $imgs = jQuery('#m_slider .ms1'),
    imgAmount = $imgs.length;

$($imgs.css('position', 'absolute').hide().get(0)).show();

timer = setInterval(swapImages, 5000);

jQuery('#m_slider').mouseenter(function() {
    clearInterval(timer);
}).mouseleave(function() {
    timer = setInterval(swapImages, 5000);
});

function swapImages() {

    var $currentImg = $('.ms1:visible');

    var $nextImg = $('.ms1:hidden').eq(Math.floor(Math.random() *$('.ms1:hidden').length));
    var speed = 500;
    // animation speed should be the same for both images so we have a smooth change
    $currentImg.fadeOut(speed);
    $nextImg.fadeIn(speed);
}
});
于 2013-04-25T06:31:47.727 に答える