1
我在這裏遇到了問題。我試圖對角地滾動我的文檔。它採用文檔寬度和高度並在每個節元素中添加其值。我知道如何以y角度滾動它,但是cand找到一種方法使x角度滾動同步滾動寬度y角度。對角滾動Javascript
感謝您的任何提示!
這裏是我的JS:
$(function() {
var windowHeight = $(window).height();
var windowWidth = $(window).width();
var sectionsNumbers = $("#content section").length - 1;
var sectionCount = 0;
// Scroll sets
var windowScrollX = ((sectionsNumbers + 1) * windowWidth) - windowWidth;
alert(windowScrollX);
// Set mask w and h
$("#mask").css("width", windowWidth);
$("#mask").css("height", windowHeight);
$(".scrollRule").css("height", (sectionsNumbers + 1) * windowHeight);
$("#content section").each(function() {
// Defines its width and height
$(this).css("width", windowWidth);
$(this).css("height", windowHeight);
// Defines its position
$(this).css("left", sectionCount * windowWidth);
$(this).css("top", sectionCount * windowHeight);
sectionCount++;
});
// When window scrolls
$(window).scroll(function() {
var curScrollTop = $(window).scrollTop();
$("#debug").html(curScrollTop);
$("#content").css("top", "-" + curScrollTop);
});
});
我知道了!
我只需要將窗口總寬度除以窗口總滾動高度即可。謝謝大家!
你可以發佈你的HTML嗎?或者把它放在jsfiddle.net或jsbin.com上? –
這是它:http://jsfiddle.net/7CpbV/ –
可能的重複:http://stackoverflow.com/questions/9689765/how-to-scroll-diagonally-with-jquery-or-javascript –