jQuery.ScrollTo onAfter设置无法正常工作

我正在使用jQuery.ScrollTo脚本能够垂直滚动到所选图像(如果容器类“presentation”不在这里)或下一张图片并将其显示在屏幕中间。

注意:我创建了两个状态。 当用户点击任何图片时,我将“演示”类添加到所有图片的container div 。 因此,我将知道是否必须显示所选图像或下一个图像。

当用户在页面内滚动时,此模式将停止。 要做到这一点,我正在使用$(window).scroll事件。

这是我的问题:在图片上的点击事件之后,某个时候,我的class级“演示文稿”被我的$(window).scroll事件删除但我不知道如何解决它。

这是演示: http : //jsfiddle.net/qnQSP/8/

我在做什么:正如你所看到的,我想创建两种状态:“演示模式”和“无演示模式”。 当我们通过将全局类添加到我的容器“#galleries”来点击某个项目时,我激活了演示模式。

通过此类“打开”,我可以确定是否必须显示当前图像或滚动到下一个图像。

对于完全演示模式,我写了“$(window).scroll”函数。 当我们在页面内滚动时,此function退出演示模式。

但是,当我在演示模式下使用.scrollTo函数时,由于“$(window).scroll”函数,我总是退出此模式。 所以,我有全局变量“presentation_mode_stop_scrolling”来阻止它。

有时在我的scrollTo函数之后调用“$(window).scroll”函数,无法解析它。

这是我的代码:

HTML:

 

jQuery的

 $(window).scroll(function () { if(presentation_mode_stop_scrolling=="off") { $("#galleries").removeClass("picture_presentation"); } }); var picture_to_center_class = ""; var picture_to_center=""; $("#galleries #pictures-content").unbind("click"); $("#galleries #pictures-content").bind("click", function(event) { // Check if we are in the presentation mode var class_galleries = $("#galleries").attr('class'); if(class_galleries == "picture_presentation") { console.log("Presenation mode"); var new_picture = parseInt(picture_to_center_class)+1; // Stopping the scroll event to cancelled the presentation mode presentation_mode_stop_scrolling="on"; //scrolling to the next one var picture_to_center = $("#galleries ."+new_picture); $("body").scrollTo(picture_to_center, 800, {onAfter:function(){ presentation_mode_stop_scrolling="off"; console.log("galleries class: "+$("#galleries").attr('class'));} }); } else { console.log("Not presenation mode"); // We are adding the presentation mode to the DOM $("#galleries").addClass("picture_presentation"); // Get the binding element class number picture_to_center_class = $(this).attr('class'); console.log("picture_to_center: "+picture_to_center_class); picture_to_center = $("#galleries ."+picture_to_center_class); // Stoping the (windows).scroll to removed the galleries class presentation_mode_stop_scrolling="on"; $("body").scrollTo(picture_to_center, 800, {onAfter:function(){ presentation_mode_stop_scrolling="off"; console.log("galleries class: "+$("#galleries").attr('class'));} }); } });