/    Sign up×
Community /Pin to ProfileBookmark

Stop a slideshow with setTimeout by mouseover, start by mouseout

I would like to stop the following “Slideshow with setTimeout” by mouseover of elements with the class “.imageWrapper” – start by mouseout. Thank you all for your help!

Here’s the script:

`let showNextPictureGalleryImageTimeout;

$(document).on(“click”, “.picture-gallery .images img”, function() {

clearTimeout(showNextPictureGalleryImageTimeout);

const pictureGallery = $(this).closest(“.picture-gallery”);
const images = $(‘.images’, pictureGallery);
const activeImage = $(this);

$(‘img’, images).removeClass(‘active’);
activeImage.addClass(‘active’);

$(“.title”, pictureGallery).html(“”);

const currentActiveImage = $(“.fullshow img”, pictureGallery);
if(currentActiveImage.length === 0) {

$(“.fullshow”, pictureGallery).append(activeImage.clone());
$(“.title”, pictureGallery).html(activeImage.attr(“title”));
} else {

currentActiveImage.fadeTo(400,0.30, function() {
currentActiveImage.attr(“src”, activeImage.attr(“src”));
currentActiveImage.attr(“title”, activeImage.attr(“title”));
}).fadeTo(400,1, function() {
$(“.title”, pictureGallery).html(activeImage.attr(“title”));
});
}

showNextPictureGalleryImageTimeout = setTimeout(function() {

let nextActiveImage = $(‘img’, activeImage.closest(‘.imageWrapper’).next());
if(nextActiveImage.length === 0) {
nextActiveImage = $(‘img’, $(‘.imageWrapper’, pictureGallery).first());
}

nextActiveImage.trigger(‘click’);
}, 8000);

});`

I tried this code:

`let showNextPictureGalleryImageTimeout;

$(document).on(“click”, “.picture-gallery .images img”, function() {

clearTimeout(showNextPictureGalleryImageTimeout);

const pictureGallery = $(this).closest(“.picture-gallery”);
const images = $(‘.images’, pictureGallery);
const activeImage = $(this);

$(‘img’, images).removeClass(‘active’);
activeImage.addClass(‘active’);

$(“.title”, pictureGallery).html(“”);

const currentActiveImage = $(“.fullshow img”, pictureGallery);
if(currentActiveImage.length === 0) {

$(“.fullshow”, pictureGallery).append(activeImage.clone());
$(“.title”, pictureGallery).html(activeImage.attr(“title”));
} else {

currentActiveImage.fadeTo(400,0.30, function() {
currentActiveImage.attr(“src”, activeImage.attr(“src”));
currentActiveImage.attr(“title”, activeImage.attr(“title”));
}).fadeTo(400,1, function() {
$(“.title”, pictureGallery).html(activeImage.attr(“title”));
});
}

$(‘.imageWrapper img’).mouseover(function(){
clearIntervall(showNextPictureGalleryImageTimeout);
}).mouseout(function(){
showNextPictureGalleryImageTimeout = setIntervall(function() {

let nextActiveImage = $(‘img’, activeImage.closest(‘.imageWrapper’).next());
if(nextActiveImage.length === 0) {
nextActiveImage = $(‘img’, $(‘.imageWrapper’, pictureGallery).first());
}

nextActiveImage.trigger(‘click’);
}, 8000);
});

});`

Sorry, I can’t develop at all. I thought it might be a very simple snippet of code from which I can learn something for the future.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @valentinkoch1976 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...