我有下面这个jQuery脚本,可以使一个DIV变成浮动定位。(目前正常工作没有问题)
```html
您可以在此处看到它的实际应用。它是右侧的灰色框,上面写着“Poll”。
我的网站是响应式的,因此当宽度小于768像素时,投票div会移动到博客内容下方。因此,在完整浏览器宽度下,脚本运作良好,但当我调整大小时,投票div就会出现问题。
当涉及到jQuery时,我完全是个初学者——我只是一个优秀的复制粘贴者——但我想象中现有的脚本中有一种花哨的方法,可以指示它在匹配媒体查询或浏览器宽度时禁用它,以便我可以摆脱固定浮动div功能。
如果有人想要一个本地副本进行操作,这里是一个zip文件,其中包含html文件(由于我正在使用webfonts,类型可能不正确)。
```html
我有下面这个jQuery脚本,可以使一个DIV变成浮动定位。(目前正常工作没有问题)
```$(document).ready(function() {
ctop = $('#comment').offset().top - parseFloat($('#comment').css('margin-top').replace(/auto/, 0));
});
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
var abottom = $('#individual_second_tier').offset().top - parseFloat($('#individual_second_tier').css('margin-top').replace(/auto/, 0));
// whether that's below the form
if (y >= ctop) {
// if so, ad the fixed class
$('#comment').addClass('fixed');
if (y > abottom-$('#comment').height()){
$('#comment').offset({'top': abottom-$('#comment').height()-y});
}
else
{
$('#comment').offset({'top': 0 });
}
} else {
// otherwise remove it
$('#comment').removeClass('fixed');
}
var newWidth = $('#comment').parent().width();
$('#comment').width(newWidth);
});
您可以在此处看到它的实际应用。它是右侧的灰色框,上面写着“Poll”。
我的网站是响应式的,因此当宽度小于768像素时,投票div会移动到博客内容下方。因此,在完整浏览器宽度下,脚本运作良好,但当我调整大小时,投票div就会出现问题。
当涉及到jQuery时,我完全是个初学者——我只是一个优秀的复制粘贴者——但我想象中现有的脚本中有一种花哨的方法,可以指示它在匹配媒体查询或浏览器宽度时禁用它,以便我可以摆脱固定浮动div功能。
如果有人想要一个本地副本进行操作,这里是一个zip文件,其中包含html文件(由于我正在使用webfonts,类型可能不正确)。