2015-10-09 4 views
1

Я строил горизонтальный сайт на одну страницу. И за последние два дня я пробовал всевозможные вещи без везения. Наконец, я понял, как сделать гладкую работу прокрутки. Но не совсем. Он слегка скользит, но он не скользит по всему сектору.Горизонтальный Smooth Scroll One Page

Вот эта функция.

$(function() { 
      $('a[href*=#]:not([href=#])').click(function() { 
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { 
       var target = $(this.hash); 
       target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); 
       if (target.length) { 
       $('body').animate({ 
        scrollLeft: target.offset().top 
       }, 1000); 
       return false; 
       } 
      } 
      }); 
     }); 

Полный сайт можно найти по адресу levistroop.com/test

Любая помощь очень ценится !!

Бест, Леви

+1

установка Try «scrollLeft: цель. offset(). left 'вместо top. –

+0

Отлично !! Я полностью пропустил это. Спасибо. –

+0

@GreggDuncan вы можете установить это как ответ на кредит. –

ответ

1

установка Try 'scrollLeft:. Target.offset() левый' вместо верхнего

1

Просто небольшое изменение:

$(function() { 
    $('a[href*=#]:not([href=#])').click(function() { 
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { 
     var target = $(this.hash); 
     target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); 
     if (target.length) { 
     $('body').animate({ 
      scrollLeft: target.offset().left 
     }, 1000); 
     return false; 
     } 
    } 
    }); 
});