2016-03-08 68 views
0

我想在div內進行自動滾動,但是我的代碼會滾動整個頁面。我怎麼能這樣做,它只能在div中滾動?自動滾動div,但不移動整個頁面velocity.js

代碼:

<div class="banner"> 
    div class="logo"></div> 
</div> 
<div id="container"> 
    <div class="tile"></div> 
    . 
    . 
    . 
</div> 

CSS:

.banner{ 
    position: absolute; 
    width: 100%; 
    height: 50px; 
    margin-top: 5px; 
    margin-bottom: 5px; 
} 

.logo{ 
    background-image: url(image.png) center no-repeat; 
} 

#container{ 
    width: 1800px; 
    height: 1050px; 
    position: absolute; 
} 

jQuery中:

var scrollWidth = $("#container").width(); 
var scrollHeight = $("#container").height(); 
$("#container").velocity("scroll", { 
    axis: "x", 
    duration: 10000, 
    offset: scrollWidth 
}) 
.velocity("scroll", { 
    axis: "y", 
    duration: 10000, 
    offset: scrollHeight 
}); 

我上面提供的服務將與.banner一起滾動的代碼,但我想修正了自動滾動#container div時的位置。我正在使用velocity.js進行自動滾動。

回答

0

如果你在室內#container滾動則必須在速度動畫提供container財產,檢查Julian Shapiro demo

另一種解決方案可以設置橫幅的位置固定,而不是絕對