如何优化滚动条事件
怎么优化滚动条事件?
代码时这样的:
然后出现了一个问题,因为我开发环境是我的笔记本电脑,所以是小屏,虽然没在大屏上测试过,但我分析一下代码,肯定会出现这样的问题:如果屏幕太大,无法出现滚动条,那么里面的事件是无法触发,#two的内容就无法显示出来。
这种情况,该怎么办?强行“扩大”初始的窗口吗?(我初始的窗口是900px;)
附一下网站demo: www.seventh77.com 密码:111111
------解决思路----------------------
触发一下就好了,不管是否出现滚动条
$(window).bind("scroll",function () {
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
if (scrollTop + windowHeight >= scrollHeight) {
$("#two").slideDown("slow");
$(".frame").slideDown(1500);
$(".frame").css("height","560px");
$("#background").css("height","1200px");
}
}).trigger('scroll');
代码时这样的:
$(window).bind("scroll",function () {
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
if (scrollTop + windowHeight >= scrollHeight) {
$("#two").slideDown("slow");
$(".frame").slideDown(1500);
$(".frame").css("height","560px");
$("#background").css("height","1200px");
}
}
然后出现了一个问题,因为我开发环境是我的笔记本电脑,所以是小屏,虽然没在大屏上测试过,但我分析一下代码,肯定会出现这样的问题:如果屏幕太大,无法出现滚动条,那么里面的事件是无法触发,#two的内容就无法显示出来。
这种情况,该怎么办?强行“扩大”初始的窗口吗?(我初始的窗口是900px;)
附一下网站demo: www.seventh77.com 密码:111111
------解决思路----------------------
触发一下就好了,不管是否出现滚动条
$(window).bind("scroll",function () {
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
if (scrollTop + windowHeight >= scrollHeight) {
$("#two").slideDown("slow");
$(".frame").slideDown(1500);
$(".frame").css("height","560px");
$("#background").css("height","1200px");
}
}).trigger('scroll');