【发布时间】:2013-12-10 03:16:07
【问题描述】:
我需要另辟蹊径,感谢您抽出宝贵时间。我有一个基于 Zurb Foundation 的商业模板,它使用 jQuery 根据页面宽度移动几个元素。我遇到了麻烦,可能是由于对基础数学的无知,我可以用一只手。
相关的 jQuery 是一个在 doc ready 和 resize 时触发的函数:
function organize() {
var welcome = $('#welcome').remove();
var sidebar = $('#sidebar');
var innerwidth = $('body').innerWidth();
// Move the Welcome DIV - we ALWAYS do this
welcome.appendTo('#content-wrap');
// If we're mobile, let's move a few things around
if( innerwidth < 768 ) {
if (!sidebar.hasClass('mobile')) {
var sidecut = sidebar.addClass('mobile').detach();
sidecut.prependTo('#content-wrap')
}
}
// If we've gone bigger, put things back where we found them
if( innerwidth >= 768) {
if (sidebar.hasClass('mobile')) {
var sidefix = sidebar.removeClass('mobile').detach();
sidefix.insertAfter('#primary');
}
}
}
如您所见,使用 768px 断点我将侧边栏移动到顶部而不是底部,否则它将根据源顺序堆叠。我也尝试过 document.width 但 innerWidth 似乎提供了额外的像素容差。虽然中断是在 768,但我一直遇到 CSS 问题,直到 785,此时一切都会自行解决。
CSS的相关位在这里(SCSS格式)
// Shop Menu
#shopmenu {
ul {
list-style: none;
margin: 0 0 80px 0;
padding: 0;
@include display;
li {
background: $level-4;
font-size:20px;
border-bottom: 1px solid $level-3;
&:first-child {
padding: 0 10px;
font-size: 22px;
}
&:last-child {border-bottom: none;}
a {
color: rgb(25,25,25);
padding: 0 20px;
&:hover {
text-decoration: underline;
}
}
ul {
margin: 0;
padding: 0;
ul {
padding-left: 25px;
ul {
padding-left: 30px;
ul {
padding-left: 35px;
}
}
}
}
li {
background: $level-4;
font-size:17px;
&:first-child {
padding: 0;
font-size: 20px;
}
a {
padding: 0 30px;
font-size: 16px;
}
li {
border: none;
}
}
}
}
}
除了调整一些填充之外,我并没有对 CSS 中的断点做太多事情,这不是问题(如果没有那个部分,它仍然存在)。这包括检查了#content-wrap ul.products li 的附加断点,我在其中更改了% 宽度以证明LI based on this technique 的合理性。同样,即使我转到无样式列表,问题仍然存在。
希望有人在我 4 小时后醒来时发现我的笨蛋。
【问题讨论】:
标签: jquery css responsive-design sass zurb-foundation