【发布时间】:2016-06-05 00:23:43
【问题描述】:
我正在尝试实现带有标题横幅的水平滑动布局。
这是 HTML 结构:
<body>
<div id="header">
<div><a href="#one"> one </a></div>
<div><a href="#two"> two </a></div>
<div><a href="#thr"> thr </a></div>
</div>
<div id="one" class="panel"> </div>
<div id="two" class="panel"> </div>
<div id="thr" class="panel"> </div>
</body>
标题是固定的,面板提供了渐变背景(中间面板具有不同的颜色用于调试目的)。 这是 CSS:
body {
width: 6000px;
overflow: hidden;
}
.panel {
width: 33.3%;
float: left;
padding-left: 30px;
padding-right: 1040px;
margin-top: -75px;
height: 960px;
background-image: linear-gradient(to bottom, #0B88FF, #95EEFF);
}
#header {
position: fixed;
height: 75px;
margin-top: 25px;
}
#two{
background-image: linear-gradient(to bottom, #0B8800, #9E5EFF);
}
最后是管理面板间动画的函数:
$(document).ready(function() {
$("#header a").bind("click", function(event) {
event.preventDefault();
var target = $(this).attr("href");
$("html, body").stop().animate({
scrollLeft: $(target).offset().left,
scrollTop: $(target).offset().top
}, 1200);
});
});
我面临的问题如下:
1) 我尝试实现一个 jQuery 函数来在用户使用鼠标滚轮时运行幻灯片动画,但是我的测试都没有工作...结构始终相同:
$(window).scroll(function() {
if ($(this).scrollTop() > 0) {
var target // still not able to figure out who should i target
$("html, body").stop().animate({
//to the target >,<
}
});
2) 当我的浏览器窗口大小为 100% 时,一切似乎都运行良好,但如果我减小或增加缩放比例,一切都会变得混乱 >,here is an example:
【问题讨论】: