2011-01-29 17 views

risposta

0

se si desidera attivare una funzione quando fondo di vista, ha colpito parte superiore del suo sito web, è possibile utilizzare questa funzione:

$('.ModuleWrapper').waypoint(function (direction) { 
    // Codes Here 
}, { 
    offset: function() { 
     return $(this).height(); 
    } 
}); 

o quando il fondo della vista tocca la parte inferiore del contenuto, è possibile utilizzare anche questa funzione:

$('.ModuleWrapper').waypoint(function (direction) { 
    // Codes Here 
}, { 
    offset: function() { 
     return -1 * $(this).height(); 
    } 
}); 

utilizza waypoint

2

Se avete solo bisogno di sparare una volta:

$(window).scroll(function(){ 
    // This is then function used to detect if the element is scrolled into view 
    function elementScrolled(elem) 
    { 
    var docViewTop = $(window).scrollTop(); 
    var docViewBottom = docViewTop + $(window).height(); 
    var elemTop = $(elem).offset().top; 
    return ((elemTop <= docViewBottom) && (elemTop >= docViewTop)); 
    } 

    // This is where we use the function to detect if ".box2" is scrolled into view, and when it is add the class ".animated" to the <p> child element 
    if(elementScrolled('. box2')) { 


    // Your function here 

    } 
}); 

risposta completa: https://www.thewebtaylor.com/articles/how-to-detect-if-an-element-is-scrolled-into-view-using-jquery

Problemi correlati