gpt4 book ai didi

适用于智能手机的 jQuery Accordion

转载 作者:行者123 更新时间:2023-12-01 06:01:35 24 4
gpt4 key购买 nike

这个想法是,这个 Accordion 仅适用于智能手机,以提高小型设备的可用性。

但是,只有在 480 以下刷新浏览器时它才有效。

是否有一种方法可以在函数中包含一些内容,使窗口大小调整到 480 以下时浏览器会立即刷新?

手动刷新浏览器根本无法使用。

var windowWidth = $(window).width(); //retrieve current window width
function accordion() {
if (windowWidth<=480)
{


$('h3').click(function() {

$('h3').next().hide(2000);

if($(this).next().is(':hidden') == true) {

$(this).next().show(1000); }


});

}}

$(document).ready(function() {
accordion();
});

HTML 标记

                    <section class="box">

<h3>Service 1</h3>

<div class="box2"> <p></p></div>

</section><!-- end box_1 -->

<section class="box">

<h3>Service 2</h3>

<div class="box2"><p></p> </div>

</section><!-- end box_2 -->

<section class="box">

<h3>Service 3</h3>

<div class="box2"><p></p> </div>

</section><!-- end box_3 -->

</section>

最佳答案

您仅获得初始窗口宽度。

$(window).resize(function () { windowWidth = $(this).width(); });

您还需要适本地运行 accordion 并在窗口再次变宽时将其关闭。也许只需在 window.resize 方法中添加对 accordion 的调用就足够了,但我还没有测试过。

关于适用于智能手机的 jQuery Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11019352/

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