[英]Can someone please tell me why this js function doesn't run on load?
I've: 我有:
//Resize tabs - height when window size changes. Don't forget to reset niceScroll
function recalc_tab_height () {
//
var wrapper_h = $(".ui-panel-content-wrap").outerHeight();
var content_h = $(".ui-content").outerHeight();
var current_h = $(".tab1").outerHeight();
var newHeight = (wrapper_h - content_h) + current_h;
//
$(".tab1, .tab2, .tab3").css({"height":newHeight}).getNiceScroll().resize();
}
//Run once onLoad
recalc_tab_height();
That is supposed to resize lyrics section on-load to fit the screen. 那应该调整加载的歌词部分的大小以适合屏幕。 But it doesn't run at all... any ideas why?
但是它根本没有运行……有什么主意吗? it is inside ui.js
它在ui.js中
http://mac.idev.ge:800/mobile-radio/ http://mac.idev.ge:800/mobile-radio/
try 尝试
$(function() {
recalc_tab_height();
});
instead of your last line. 而不是最后一行。
$(...)
is a shortcut for $(document).ready(...)
and is executed as soon as your page is entirely loaded, so that you can deal with DOM
element properties. $(...)
是$(document).ready(...)
的快捷方式,并且在页面完全加载后立即执行,因此您可以处理DOM
元素属性。
Try this : Need to set $(document).ready
试试这个:需要设置
$(document).ready
$(document).ready(function(){
//Run once onLoad
recalc_tab_height();
});
To load this function either you should use this on body as 要加载此功能,您应该在身体上使用它作为
<body onload="recalc_tab_height();" >
or by jquery 或通过jQuery
$(document).ready(function() {
recalc_tab_height();
});
Wrap the function call when the dom is ready.Try like this 准备好dom后包装函数调用。
$(document).ready(function(){
recalc_tab_height();
});
A page can't be manipulated safely until the document is " ready ." 在文档“ 准备就绪 ”之前,无法安全地操纵页面。 jQuery detects this state of readiness for you.
jQuery为您检测到这种就绪状态。 Code included inside $(document).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.
$(document).ready()中包含的代码仅在页面文档对象模型(DOM)准备好执行JavaScript代码后才能运行。 Code included inside $(window).load(function() { ... }) will run once the entire page (images or iframes), not just the DOM, is ready.
一旦整个页面(图像或iframe)(不仅是DOM)准备就绪, $(window).load(function(){...})中包含的代码将运行。
So you have to call your function inside $(document).ready({...});
因此,您必须在
$(document).ready({...});
内调用函数$(document).ready({...});
or $(window).load(function() { ... });
或
$(window).load(function() { ... });
我将css()更改为animate(),并且有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.