gpt4 book ai didi

javascript - 将 jQuery 事件从单击更改为加载

转载 作者:行者123 更新时间:2023-12-02 16:39:11 24 4
gpt4 key购买 nike

我正在使用以下 onclick 函数,该函数在单击时触发对象变为全屏。我希望该对象在页面加载时全屏显示,而无需单击。

  fbNav.find('ul li.fullscreen').on('click', function(e){
if(!fullscreen) {
fbFullscreen.show();
fbFullscreen.append(fbCont);

$window.trigger('resize');
} else {
fbParent.append(fbCont);
fbFullscreen.hide();

$window.trigger('resize');
}

fullscreen = !fullscreen;
});

我怎样才能实现这个目标?

最佳答案

您最好将主要逻辑放在一个函数中,并在就绪并单击时调用相同的函数。

function fullscreen(){
if(!fullscreen) {
fbFullscreen.show();
fbFullscreen.append(fbCont);

$window.trigger('resize');
} else {
fbParent.append(fbCont);
fbFullscreen.hide();

$window.trigger('resize');
}

fullscreen = !fullscreen;
}

//will be executed when page loads
$(document).ready(function(){
fullscreen();
});

//will be executed on click
fbNav.find('ul li.fullscreen').on('click', function(e){
fullscreen();
});

关于javascript - 将 jQuery 事件从单击更改为加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27646286/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com