[英]jquery window resize event not working on initial load
I know flex box is an option to change the orders of divs however I am using a bit of jquery instead of installing flexbox for one needed feature 我知道可以使用flex box来更改div的顺序,但是我使用了一些jquery而不是为一个所需的功能安装flexbox
This is the script I am using which works fine when resizing the window 这是我使用的脚本,在调整窗口大小时可以正常工作
<script type="text/javascript">
$(document).load($(window).bind("resize", listenWidth));
function listenWidth( e ) {
if($(window).width()>910)
{
$(".loginblock").remove().insertAfter($("#step1"));
} else {
$(".loginblock").remove().insertBefore($(".regblock"));
}
}
</script>
Is there a simple way to edit my script to know what size the screen is on load and make the changes needed? 有没有一种简单的方法可以编辑我的脚本,以了解加载屏幕的大小并进行所需的更改?
Thanks! 谢谢!
You bind the function on resize... Ok. 您可以在调整大小时绑定该函数...确定。
You only need to also trigger it onload. 您只需要在加载时触发它即可。
<script type="text/javascript">
$(document).load($(window).bind("resize", listenWidth));
function listenWidth( e ) {
if($(window).width()>910)
{
$(".loginblock").remove().insertAfter($("#step1"));
} else {
$(".loginblock").remove().insertBefore($(".regblock"));
}
}
listenWidth(); // Add this here to execute the funtion onload.
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.