Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Funzione scroll page

  1. #1
    Utente di HTML.it L'avatar di lorca
    Registrato dal
    Nov 2007
    Messaggi
    17

    Funzione scroll page

    Buongiorno, ho trovato questo script per effettuare lo scroll della pagina su dei collegamenti (tipo ancoraggio) il risultato è uno scroll in movimento.
    Se lo uso su una pagina html funziona correttamente se lo uso su una pagina in php mi va a scatti, secondo voi qual'è il problema. Grazie
    Vi posto il codice:

    <script>
    $(document).ready(function() {
    function filterPath(string) {
    return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
    }
    var locationPath = filterPath(location.pathname);
    var scrollElem = scrollableElement('html', 'body');

    $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if ( locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
    var $target = $(this.hash), target = this.hash;
    if (target) {
    var targetOffset = $target.offset().top;
    $(this).click(function(event) {
    event.preventDefault();
    $(scrollElem).animate({scrollTop: targetOffset}, 800, function() {
    location.hash = target;
    });
    });
    }
    }
    });

    // use the first element that is "scrollable"
    function scrollableElement(els) {
    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
    var el = arguments[i],
    $scrollElement = $(el);
    if ($scrollElement.scrollTop()> 0) {
    return el;
    } else {
    $scrollElement.scrollTop(1);
    var isScrollable = $scrollElement.scrollTop()> 0;
    $scrollElement.scrollTop(0);
    if (isScrollable) {
    return el;
    }
    }
    }
    return [];
    }

    });
    </script>
    LORCA

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    jquery e' incluso correttamente?
    verifica la console javascript

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.