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

时间:2013-03-19 13:48:46

标签: jquery scroll

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

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

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

以下是我的问题:在图片上发生点击事件之后,我的$(window).scroll事件会删除我的课程“演示文稿”,但我不知道如何修复它。

以下是演示:http://jsfiddle.net/qnQSP/8/

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

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

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

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

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

这是我的代码:

HTML:

<div id="galleries">

<div id="pictures-content" class="1"><img src="http://www.sb-designs.co.uk/ckfinder/userfiles/images/free%20web%20hosting.jpg"></div>


<div id="pictures-content" class="2"><img src="http://www.mastercreations.net/wp-content/uploads/2012/10/5.jpg"></div>


<div id="pictures-content" class="3"><img src="http://www.sb-designs.co.uk/ckfinder/userfiles/images/free%20web%20hosting.jpg"></div>


<div id="pictures-content" class="4"><img src="http://www.webdesign4essex.co.uk/images/essex_website_design.jpg"></div>


<div id="pictures-content" class="5"><img src="http://www.mastercreations.net/wp-content/uploads/2012/10/5.jpg"></div>

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'));} });
         }
    });

0 个答案:

没有答案