我試圖獲得它,以便當您點擊旋轉木馬時,頁面將調整爲在中心有旋轉木馬。這個網站(http://studionewwork.com/)顯示了這一點,當你點擊他們的旋轉木馬。我仍然在學習Jquery,所以我還沒有熟練掌握命令。如何調整頁面滾動到中心點擊旋轉木馬?
http://jsfiddle.net/8bJUc/614/
$(document).ready(function() {
$("#owl-demo").owlCarousel({
navigation: true,
pagination: true,
lazyLoad: true
});
});
$('.owl-demo').on('click', function(e) {
var el = $(e.target.getAttribute('href'));
var elOffset = el.offset().top;
var elHeight = el.height();
var windowHeight = $(window).height();
var offset;
if (elHeight < windowHeight) {
offset = elOffset - ((windowHeight/2) - (elHeight/2));
}
else {
offset = elOffset;
}
var speed = 700;
$('html, body').animate({scrollTop:offset}, speed);
});
sry對我來說不是很清楚http://owlgraphic.com/owlcarousel/demos/one.html – Osgux
@Osgux我試圖讓每個轉盤調整到視口的中間,當你點擊/與它互動時,就像我發佈的示例網站一樣... – user2252219