Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery.ScrollTo and scroll event aren't working corectly
    primarykey
    data
    text
    <p>I haven't find any solution for this question so I'm asking it again, here is the previous question link: <a href="https://stackoverflow.com/questions/15501304/jquery-scrollto-onafter-settings-isnt-working-correctly">jQuery.ScrollTo onAfter settings isn&#39;t working correctly</a></p> <p>I'm using the jQuery.ScrollTo script to be able to vertically scroll to the selected image or to the next image. (This depend if the "presentation" class is attach to my images container) </p> <p>To do it, I have created two states:"the presentation mode" and the "no presentation mode".</p> <p>I'm activate the presentation mode when we are clicking on an image by adding the global class "presentation" to my container "#galleries". With this class "on", I can determine if I have to display the current image or scroll to the next one. </p> <p>To quite the presentation mode, I wrote the "$(window).scroll" function. This function is quitting the presentation mode when the user is scrolling inside the page.</p> <p>Problem: when I was using the .scrollTo event during the presentation mode, I was always quitting the "presentation" mode because of the "$(window).scroll" function. So, I had the global variable "presentation_mode_stop_scrolling" to stop it, but this isn't working</p> <p>Here is my problem: After a click event on a picture, sometime, my class "presentation" is removed by my $(window).scroll function, any ideas???</p> <p>Here is Demo: <a href="http://jsfiddle.net/qnQSP/12/" rel="nofollow noreferrer">http://jsfiddle.net/qnQSP/12/</a></p> <p>Here is my code:</p> <pre><code>&lt;div id="galleries"&gt; &lt;div id="pictures-content" class="1"&gt;&lt;img src="http://www.sb-designs.co.uk/ckfinder/userfiles/images/free%20web%20hosting.jpg"&gt;&lt;/div&gt; &lt;div id="pictures-content" class="2"&gt;&lt;img src="http://www.mastercreations.net/wp-content/uploads/2012/10/5.jpg"&gt;&lt;/div&gt; &lt;div id="pictures-content" class="3"&gt;&lt;img src="http://www.sb-designs.co.uk/ckfinder/userfiles/images/free%20web%20hosting.jpg"&gt;&lt;/div&gt; &lt;div id="pictures-content" class="4"&gt;&lt;img src="http://www.webdesign4essex.co.uk/images/essex_website_design.jpg"&gt;&lt;/div&gt; &lt;div id="pictures-content" class="5"&gt;&lt;img src="http://www.mastercreations.net/wp-content/uploads/2012/10/5.jpg"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p></p> <p>My script</p> <pre><code>presentation_mode_stop_scrolling = "off"; // Calling functions $(document).ready(function(){ // ADD THE POST ANIMATION ON PICTURE TO CENTER IT IN THE MIDDLE OF THE SCREEN 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") { // WE ARE IN THE PRESENTATION MODE // GO TO THE NEXT ONE $("#galleries").addClass('picture_presentation'); console.log("WE ARE IN THE PRESENTATION MODE, GO TO THE NEXT ONE"); 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(){ console.log("galleries class: "+$("#galleries").attr('class')); presentation_mode_stop_scrolling="off"; return false; console.log("removed class"); }}); } else { // THE PRESENTATION MODE // FOCUS THIS ONE // We are adding the presentation mode to the DOM $("#galleries").addClass("picture_presentation"); console.log("PRESENTATION MODE, FOCUS THIS ONE, ADDING THE PRESENTATION CLASS "); // 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"; return false; $("#galleries").addClass('picture_presentation'); // console.log("galleries class: "+$("#galleries").attr('class')); } }); } return false; }); // ADD THE FUNCTION TO REMOVE THE USER FROM THE PRESENTATION MODE $(window).scroll(function () { // console.log("presentation_mode_stop_scrolling: "+presentation_mode_stop_scrolling); if(presentation_mode_stop_scrolling=="off") { $("#galleries").removeClass("picture_presentation"); console.log("THE PRESENTATION MODE HAS BEEN REMOVED"); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload