Как прокрутить окно с помощью $ JQuery .scrollTo () функция

Это то, что я использовал для этого (фрагмент, который у меня был некоторое время):

public function scanLatestFile($directory) {
    // ignore any files that you don't want scanned
    $ignoredFiles = array('.index.php', '.htaccess');

    // Create new array to store the list of files
    $filesToSearch = array();

    // Scan the directory passed in
    foreach (scandir($directory) as $file) {
        if (in_array($file, $ignoredFiles)) continue;

        // Add the filemtime so you can sort it
        $filesToSearch[$file] = filemtime($dir . '/' . $file);
    }

    // Sort by latest file
    arsort($filesToSearch);
    $filesToSearch = array_keys($filesToSearch);

    // Return latest file if it exists
    return ($filesToSearch) ? $filesToSearch : false;
}

Это вернет последний файл в каталоге, также файлы игнорирования хорошо исключить все, что вы не хотите.

95
задан 7 May 2009 в 04:13
поделиться

3 ответа

If it's not working why don't you try using jQuery's scrollTop method?

$("#id").scrollTop($("#id").scrollTop() + 100);

If you're looking to scroll smoothly you could use basic javascript setTimeout/setInterval function to make it scroll in increments of 1px over a set length of time.

94
ответ дан 24 November 2019 в 05:42
поделиться

Looks like you've got the syntax slightly wrong... I'm assuming based on your code that you're trying to scroll down 100px in 800ms, if so then this works (using scrollTo 1.4.1):

$.scrollTo('+=100px', 800, { axis:'y' });
7
ответ дан 24 November 2019 в 05:42
поделиться

jQuery теперь поддерживает scrollTop в качестве переменной анимации.

$("#id").animate({"scrollTop": $("#id").scrollTop() + 100});

Для плавной прокрутки больше не нужно использовать setTimeout / setInterval.

41
ответ дан 24 November 2019 в 05:42
поделиться
Другие вопросы по тегам:

Похожие вопросы: