清除Jquery css更改的大小刷新
clearing Jquery css changes on resize refresh
您可以从我的示例中看到。我试图使它,当窗口的大小低于1000px;CSS被清除,以便我的。CSS文件可以接管。
如果窗口大小小于1000px,它会起作用但反之则不行
$(window).resize(function(){
if ($(window).width() >= 1000) {
var length = $('#left').height() - $('#sidebar').height() + $('#left').offset().top;
$(window).scroll(function () {
var scroll = $(this).scrollTop();
var height = $('#sidebar').height() + 'px';
if (scroll < $('#left').offset().top) {
$('#sidebar').css({
'position': 'absolute',
'top': '0'
});
} else if (scroll > length) {
$('#sidebar').css({
'position': 'absolute',
'bottom': '0',
'top': 'auto'
});
} else {
$('#sidebar').css({
'position': 'fixed',
'top': '0',
'height': height
});
}
});
}
else if ($(window).width() <= 1000) {
$('#sidebar').css({
'position': '',
'bottom': '',
'top': ''
});
$('#left').css({
'position': '',
'bottom': '',
'top': ''
});
}
});
我认为代码的主要问题不是工作的方式,因为滚动函数是在窗口调整大小函数;我认为你只需要稍微打乱一下这些东西:
$(window).scroll(function () {
if ($(window).width() >= 1000) {
var length = $('#left').height() - $('#sidebar').height() + $('#left').offset().top;
var scroll = $(this).scrollTop();
var height = $('#sidebar').height() + 'px';
if (scroll < $('#left').offset().top) {
$('#sidebar').css({
'position': 'absolute',
'top': '0'
});
} else if (scroll > length) {
$('#sidebar').css({
'position': 'absolute',
'bottom': '0',
'top': 'auto'
});
} else {
$('#sidebar').css({
'position': 'fixed',
'top': '0',
'height': height
});
}
}
});
$(window).resize(function(){
if ($(window).width() < 1000) {
$('#sidebar').css({
'position': '',
'bottom': '',
'top': ''
});
$('#left').css({
'position': '',
'bottom': '',
'top': ''
});
}
});
相关文章:
- css媒体查询请求后刷新jQuery插件
- 刷新jquery中弹出的ui对话框
- 在'之后刷新jQuery Mobile元素;手动'操纵
- 不断刷新 jQuery 数据
- 如何刷新 jquery 移动复选框主题
- 刷新 jQuery 移动范围滑块
- 刷新 jquery 数据表
- 刷新 JQuery Mobile 中的列表视图和复选框
- 使用 ajax 动态刷新 jquery 数据表
- 更改状态以刷新 Jquery 的按钮
- 刷新 jquery 选项卡中的表单字段
- 从DOM刷新jQuery DataTable-无AJAX
- 在Ember.js视图中刷新jQuery绑定的正确方法是什么
- 正在刷新jQuery对话框数据
- 在django中发布一些内容而不刷新(JQuery、AJAX?)
- 如何在页面调整上刷新jQuery Mobile样式
- 如何在动态添加行后刷新JQuery移动表
- 刷新jquery mobile中的弹出内容
- 刷新jquery移动页面时会发生什么
- 如何刷新jQuery.ech()函数