2015-12-03 90 views
0

我在我的網站上有一個Read More/Read Less按鈕,用於產品描述。Read Less按鈕滾動頁面

我的問題是,在擴展描述的底部,單擊Read Less按鈕時,它會縮短描述的預期時間,但頁面不會回滾到描述div的頂部,所以我只剩下了看着頁面頁腳。

有沒有辦法讓它回滾到div的頂部?

+0

你嘗試用錨一個簡單的鏈接? –

+0

我做到了,是的,但無濟於事。也許是JS以某種方式干擾?該網站是[here](http://radshaperc.businesscatalyst.com/scale-and-off-road/scale-rock-crawling-kits/1-10-gs01-komodo-truck-scale-crawler-kit#product - 描述) – ConduciveMammal

+0

你試過[這篇文章](http://stackoverflow.com/questions/18071046/smooth-scroll-to-specific-div-on-click)或[這篇文章](http:// stackoverflow。 com/questions/3163615/how-to-scroll-html-page-to-given-anchor-using-jquery-or-javascript) –

回答

0

對於未來的讀者,這個Fiddle有一個完美的腳本。

的HTML

<div class="first"><button type="button">Click Me!</button></div> 
<div class="second">Hi</div> 

JavaScript的

$("button").click(function() { 
    $('html,body').animate({ 
     scrollTop: $(".second").offset().top}, 
     'slow'); 
}); 

的CSS

.first { 
    width: 100%; 
    height: 1000px; 
    background: #ccc; 
} 

.second { 
    width: 100%; 
    height: 1000px; 
    background: #999; 
}