[英]The function starting too early
我正在使用jQuery ajax构建联系系统。 窗体的div有一个高度,所以我认为如果单击输入(OnFocus)时div会变大,而当您向上或向下滚动时div会返回到它的常规高度,那会很好。 问题是单击后,div变大,然后立即返回到其常规高度。 这是我的代码:
var big = false,
lastpalce = "",
position = "";
function contectboxreturn() {
if (big) {
$("#contact").animate({
"height": "515px"
}, 400);
$("#showclosebutton").hide(fast);
big = false;
}
}
function contectboxresize() {
if (!big) {
big = true;
lastpalce = $(this).scrollTop();
position = $("#contact").offset();
$("html, body").animate({
scrollTop: position.top + "px"
}, 400);
$("#contact").animate({
"height": "100%"
}, 400);
$("#showclosebutton").show(fast);
$(function () {
$(window).scroll(function () {
if (position.top != $(this).scrollTop()) {
contectboxreturn();
}
});
});
}
}
尝试将滚动事件放置在contectboxresize()函数之外,如下所示:
var big = false,
lastpalce = "",
position = "";
$(function () {
$(window).scroll(function () {
if (position.top != $(this).scrollTop()) {
contectboxreturn();
}
});
});
function contectboxreturn() {
if (big) {
$("#contact").animate({
"height": "515px"
}, 400);
$("#showclosebutton").hide(fast);
big = false;
}
}
function contectboxresize() {
if (!big) {
big = true;
lastpalce = $(this).scrollTop();
position = $("#contact").offset();
$("html, body").animate({
scrollTop: position.top + "px"
}, 400);
$("#contact").animate({
"height": "100%"
}, 400);
$("#showclosebutton").show(fast);
}
}
将Big设置为TRUE作为动画的回调。 像这样
$("#contact").animate({
"height": "100%"
}, 400, function(){
big = true;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.