Jquery .resize 不会被触发
Jquery .resize won't be triggered
在 W3School 之后,我尝试了以下方法来触发调整大小事件:
$(window).ready(function(){
$(window).resize(function(){
if($(".formEvent").length){ // If element exist
addEventForm($("span.active")); // resize process
}
});
console.log($(window).data("events"));
});
为什么他不会触发我的事件?
编辑:addEventForm 起作用,因为当点击时他会按时触发以创建我的元素。
编辑2:
这是 addEventform 函数:
function addEventForm(jour){
if(!$(".formEvent").length){
jour.closest("tr").after("<form class='formEvent'><div class='curseur'></div></form>");
}
var percent = jour.offset().left-jour.closest("tr").offset().left+parseInt(jour.css("margin-left").replace("px", ""))+ parseInt(jour.css("padding-left").replace("px", ""))+parseInt(jour.css("border-left-width").replace("px", ""));
$(".formEvent .curseur").css({"top" : "-15px" , "left": percent+"px"});
$(".formEvent").show()
}
我试图将控制台日志放入您的调整大小函数中,并按预期触发了它。
$(window).ready(function(){
$(window).resize(function(){
console.log('check');
if($(".formEvent").length){ // If element exist
addEventForm($("span.active")); // resize process
}
});
console.log($(window).data("events"));
});
http://codepen.io/anon/pen/PNLoRb?editors=1112
您的 if 语句中一定有什么地方出了问题。
我修正了我的错误。真的很晦涩...
window.onresize = function(){
if($(".formEvent").length){
addEventForm($("span.active"));
}
};
使用 Javascript API,一切正常。所以让我们保留这个。
在 W3School 之后,我尝试了以下方法来触发调整大小事件:
$(window).ready(function(){
$(window).resize(function(){
if($(".formEvent").length){ // If element exist
addEventForm($("span.active")); // resize process
}
});
console.log($(window).data("events"));
});
为什么他不会触发我的事件?
编辑:addEventForm 起作用,因为当点击时他会按时触发以创建我的元素。
编辑2:
这是 addEventform 函数:
function addEventForm(jour){
if(!$(".formEvent").length){
jour.closest("tr").after("<form class='formEvent'><div class='curseur'></div></form>");
}
var percent = jour.offset().left-jour.closest("tr").offset().left+parseInt(jour.css("margin-left").replace("px", ""))+ parseInt(jour.css("padding-left").replace("px", ""))+parseInt(jour.css("border-left-width").replace("px", ""));
$(".formEvent .curseur").css({"top" : "-15px" , "left": percent+"px"});
$(".formEvent").show()
}
我试图将控制台日志放入您的调整大小函数中,并按预期触发了它。
$(window).ready(function(){
$(window).resize(function(){
console.log('check');
if($(".formEvent").length){ // If element exist
addEventForm($("span.active")); // resize process
}
});
console.log($(window).data("events"));
});
http://codepen.io/anon/pen/PNLoRb?editors=1112
您的 if 语句中一定有什么地方出了问题。
我修正了我的错误。真的很晦涩...
window.onresize = function(){
if($(".formEvent").length){
addEventForm($("span.active"));
}
};
使用 Javascript API,一切正常。所以让我们保留这个。