Fanybox gallery stop autoplay on hover

徘徊边缘 提交于 2019-12-25 12:00:32

问题


Is there a solution to stop the autoPlay if the user first clicks the "next" button? Or to stop the autoPlay if user hovers the image?


回答1:


You could use the $.fancybox.play() method to toggle the fancybox (auto) slideshow on mouse hover within the afterShow callback like :

jQuery(document).ready(function ($) {
    $(".fancybox").fancybox({
        autoPlay: true, // starts slideshow
        afterShow: function () {
            $(".fancybox-outer").on("mouseover", function () {
                $.fancybox.play(false); // stops slideshow
            });
        }
    }); // fancybox
}); // ready

Notice we are targeting the .fancybox-outer selector since you could be hovering the navigation arrows area(s), and that wouldn't stop the slideshow.

See JSFIDDLE

NOTE: this is for fancybox v2.x



来源:https://stackoverflow.com/questions/27427239/fanybox-gallery-stop-autoplay-on-hover

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!