我想要做的是制作一个简单的 html/css 水平滑块来生成整个视口。
我已经有一段 javascript 可以计算用户视口并为某些 div 提供所需的宽度/高度,但我似乎无法让按钮左右动画所需的像素数量。(通过getviewport.js计算得到)
我知道我已经接近了,我只是不知道如何将变量 viewportwidth 获取到我的按钮。
这是 getviewport.js
function resize() {
if (typeof window.innerWidth != 'undefined') {
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined' & typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
viewportwidth = document.documentElement.clientWidth,
viewportheight = document.documentElement.clientHeight
}
// older versions of IE
else {
viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
viewportheight = document.getElementsByTagName('body')[0].clientHeight
}
document.getElementById("portfolio").style.height = viewportheight+"px";
document.getElementById("portfolio1").style.height = viewportheight+"px";
document.getElementById("portfolio2").style.height = viewportheight+"px";
document.getElementById("portfolio3").style.height = viewportheight+"px";
document.getElementById("portfolio1").style.width = viewportwidth+"px";
document.getElementById("portfolio2").style.width = viewportwidth+"px";
document.getElementById("portfolio3").style.width = viewportwidth+"px";
}
这是动画和按钮脚本:
<script language="javascript">
function slider_animate(px) {
$('#moving_part').animate({
'marginLeft' : px
});
}
</script>
<input type="button" value="Move Left" onclick="slider_animate('-=viewportwidth')" />
<input type="button" value="Move Right" onclick="slider_animate('+=viewportwidth')" />