Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使li项目框按顺序弹出jQuery_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使li项目框按顺序弹出jQuery

Javascript 使li项目框按顺序弹出jQuery,javascript,jquery,html,Javascript,Jquery,Html,我有一个页脚列表: <footer id="footer"> <ul> <li> <h2> x </h2> <h3> xx </h3> <p>xxx</p> <p> xxxx </p> </li> &l

我有一个页脚列表:

<footer id="footer">
    <ul>
        <li>
            <h2> x </h2>
            <h3> xx  </h3>
            <p>xxx</p>
            <p> xxxx </p>
        </li>
        <li>
            <h2> x  </h2>
            <h3> xx </h3>
            <p>xx </p>
            <p> xx </p>
        </li>
        <li>
            <h2> x </h2>
            <h3> xx </h3>
            <p>xx</p>
            <p> xxx</p>
        </li>
    </ul>
</footer>
我想这些ul盒子,在他们当前的弹出链接被点击后,要么按顺序一个接一个地填充内容,要么让盒子自己一次弹出一个。在我能做得更好的地方进行输入也很有帮助;我是新手。奖励:当有问题的两个链接再次被点击关闭时,如何使框按顺序恢复?谢谢大家

编辑:弹出页脚的两个链接位于此处,联系人链接和手机图像:

        <section id="side">
            <nav class="sidebar"><img class="logo" src="images/logo.png"></img>
                <ul>
                    <li> <a href="#"> About </a></li>
                    <li> <a href="docs.html"> Providers </a></li>
                    <li> <a href="#"> Quality </a> </li>
                    <li> <a href="#"> Contact </a> </li>
                </ul>
                <img id="add" src="images/phoner.png"></img>
            </nav>
        </section>

像这样的?如果是,以下是修改:

从页脚css中删除显示:无 将display:none添加到页脚ul li css 修改javascript代码

以下是单击后要使用的js:

toggleTimer=500;
    $( "#footer" ).find("ul").find("li").each(function() { 
        jQuery(this).toggle(toggleTimer);
        toggleTimer=toggleTimer+500;
    });

像这样的?如果是,以下是修改:

从页脚css中删除显示:无 将display:none添加到页脚ul li css 修改javascript代码

以下是单击后要使用的js:

toggleTimer=500;
    $( "#footer" ).find("ul").find("li").each(function() { 
        jQuery(this).toggle(toggleTimer);
        toggleTimer=toggleTimer+500;
    });

像这样的?如果是,以下是修改:

从页脚css中删除显示:无 将display:none添加到页脚ul li css 修改javascript代码

以下是单击后要使用的js:

toggleTimer=500;
    $( "#footer" ).find("ul").find("li").each(function() { 
        jQuery(this).toggle(toggleTimer);
        toggleTimer=toggleTimer+500;
    });

像这样的?如果是,以下是修改:

从页脚css中删除显示:无 将display:none添加到页脚ul li css 修改javascript代码

以下是单击后要使用的js:

toggleTimer=500;
    $( "#footer" ).find("ul").find("li").each(function() { 
        jQuery(this).toggle(toggleTimer);
        toggleTimer=toggleTimer+500;
    });

我想你想点击每一个,然后显示下一个,对吗? 然后,您可以使用.next()jquery属性来分配单击侦听器以切换下一个元素

$(document).ready(function() {
    //start with all LI hidden
    $('#footer').find('li').hide();
    //add click listener to the id='add' element to toggle the first LI
    $( "#add" ).click(function() {
            //if none are visible, show the first one, else hide them all
            if ($('#footer').find('li').first().css('display') == 'none' ) {
                //show the fist LI
                $( "#footer" ).find('li').first().toggle( "fast" );
            } else {
                //hide them all
                $('#footer').find('li').hide();
            }
        });
    //add listener to each LI to toggle the NEXT one
    $('#footer').find('li').click(function(){
        $(this).next().toggle("fast");
    });
});
。。。在你的评论之后

或者,您可以在每次单击时显示第一个隐藏的,如下所示:

$(document).ready(function() {
    //start with all LI hidden
    $('#footer').find('li').hide();
    //add click listener to the id='add' element to toggle the first LI
    $( "#add" ).click(
        function() {
            //if NO LI are hidden, hide them all, else show one at a time
            if ( $('#footer').find('li:hidden').size()==0 ) {
                //hide them all
                $('#footer').find('li').hide();     
            } else {
                //show the first hidden LI
                $('#footer').find('li:hidden').first().show('fast');
            }
        }
    );
});

这就是你要找的吗

我想你想点击每一个,然后显示下一个,对吗? 然后,您可以使用.next()jquery属性来分配单击侦听器以切换下一个元素

$(document).ready(function() {
    //start with all LI hidden
    $('#footer').find('li').hide();
    //add click listener to the id='add' element to toggle the first LI
    $( "#add" ).click(function() {
            //if none are visible, show the first one, else hide them all
            if ($('#footer').find('li').first().css('display') == 'none' ) {
                //show the fist LI
                $( "#footer" ).find('li').first().toggle( "fast" );
            } else {
                //hide them all
                $('#footer').find('li').hide();
            }
        });
    //add listener to each LI to toggle the NEXT one
    $('#footer').find('li').click(function(){
        $(this).next().toggle("fast");
    });
});
。。。在你的评论之后

或者,您可以在每次单击时显示第一个隐藏的,如下所示:

$(document).ready(function() {
    //start with all LI hidden
    $('#footer').find('li').hide();
    //add click listener to the id='add' element to toggle the first LI
    $( "#add" ).click(
        function() {
            //if NO LI are hidden, hide them all, else show one at a time
            if ( $('#footer').find('li:hidden').size()==0 ) {
                //hide them all
                $('#footer').find('li').hide();     
            } else {
                //show the first hidden LI
                $('#footer').find('li:hidden').first().show('fast');
            }
        }
    );
});

这就是你要找的吗

我想你想点击每一个,然后显示下一个,对吗? 然后,您可以使用.next()jquery属性来分配单击侦听器以切换下一个元素

$(document).ready(function() {
    //start with all LI hidden
    $('#footer').find('li').hide();
    //add click listener to the id='add' element to toggle the first LI
    $( "#add" ).click(function() {
            //if none are visible, show the first one, else hide them all
            if ($('#footer').find('li').first().css('display') == 'none' ) {
                //show the fist LI
                $( "#footer" ).find('li').first().toggle( "fast" );
            } else {
                //hide them all
                $('#footer').find('li').hide();
            }
        });
    //add listener to each LI to toggle the NEXT one
    $('#footer').find('li').click(function(){
        $(this).next().toggle("fast");
    });
});
。。。在你的评论之后

或者,您可以在每次单击时显示第一个隐藏的,如下所示:

$(document).ready(function() {
    //start with all LI hidden
    $('#footer').find('li').hide();
    //add click listener to the id='add' element to toggle the first LI
    $( "#add" ).click(
        function() {
            //if NO LI are hidden, hide them all, else show one at a time
            if ( $('#footer').find('li:hidden').size()==0 ) {
                //hide them all
                $('#footer').find('li').hide();     
            } else {
                //show the first hidden LI
                $('#footer').find('li:hidden').first().show('fast');
            }
        }
    );
});

这就是你要找的吗

我想你想点击每一个,然后显示下一个,对吗? 然后,您可以使用.next()jquery属性来分配单击侦听器以切换下一个元素

$(document).ready(function() {
    //start with all LI hidden
    $('#footer').find('li').hide();
    //add click listener to the id='add' element to toggle the first LI
    $( "#add" ).click(function() {
            //if none are visible, show the first one, else hide them all
            if ($('#footer').find('li').first().css('display') == 'none' ) {
                //show the fist LI
                $( "#footer" ).find('li').first().toggle( "fast" );
            } else {
                //hide them all
                $('#footer').find('li').hide();
            }
        });
    //add listener to each LI to toggle the NEXT one
    $('#footer').find('li').click(function(){
        $(this).next().toggle("fast");
    });
});
。。。在你的评论之后

或者,您可以在每次单击时显示第一个隐藏的,如下所示:

$(document).ready(function() {
    //start with all LI hidden
    $('#footer').find('li').hide();
    //add click listener to the id='add' element to toggle the first LI
    $( "#add" ).click(
        function() {
            //if NO LI are hidden, hide them all, else show one at a time
            if ( $('#footer').find('li:hidden').size()==0 ) {
                //hide them all
                $('#footer').find('li').hide();     
            } else {
                //show the first hidden LI
                $('#footer').find('li:hidden').first().show('fast');
            }
        }
    );
});

这就是你要找的吗

也许是这样的

$(document).ready(function() {
    var $footer = $("#footer").hide(),
        $footerItems = $footer.find("ul li").hide(),
        footerState = 0;
    $("#add, .sidebar ul li").click(function (e) {
        e.preventDefault();
        footerState = !footerState;
        var method = footerState ? 'show' : 'hide';
        if(footerState) $footer.show();
        $footerItems.get().reduce(function (p, li) {
            return p.then(function() {
                return $(li)[method]('slow').promise();
            });
        }, $.when()).then(function() {
            if(!footerState) $footer.hide();
        });
    });
});

可能是这样的吧

$(document).ready(function() {
    var $footer = $("#footer").hide(),
        $footerItems = $footer.find("ul li").hide(),
        footerState = 0;
    $("#add, .sidebar ul li").click(function (e) {
        e.preventDefault();
        footerState = !footerState;
        var method = footerState ? 'show' : 'hide';
        if(footerState) $footer.show();
        $footerItems.get().reduce(function (p, li) {
            return p.then(function() {
                return $(li)[method]('slow').promise();
            });
        }, $.when()).then(function() {
            if(!footerState) $footer.hide();
        });
    });
});

可能是这样的吧

$(document).ready(function() {
    var $footer = $("#footer").hide(),
        $footerItems = $footer.find("ul li").hide(),
        footerState = 0;
    $("#add, .sidebar ul li").click(function (e) {
        e.preventDefault();
        footerState = !footerState;
        var method = footerState ? 'show' : 'hide';
        if(footerState) $footer.show();
        $footerItems.get().reduce(function (p, li) {
            return p.then(function() {
                return $(li)[method]('slow').promise();
            });
        }, $.when()).then(function() {
            if(!footerState) $footer.hide();
        });
    });
});

可能是这样的吧

$(document).ready(function() {
    var $footer = $("#footer").hide(),
        $footerItems = $footer.find("ul li").hide(),
        footerState = 0;
    $("#add, .sidebar ul li").click(function (e) {
        e.preventDefault();
        footerState = !footerState;
        var method = footerState ? 'show' : 'hide';
        if(footerState) $footer.show();
        $footerItems.get().reduce(function (p, li) {
            return p.then(function() {
                return $(li)[method]('slow').promise();
            });
        }, $.when()).then(function() {
            if(!footerState) $footer.hide();
        });
    });
});

我试图准确地理解您的代码所产生的结果与预期的结果相反。实际上,我无法在这把小提琴中复制太多内容,你能修改它使其与你看到的完全一致吗?
#add
按钮在哪里?什么是“当前弹出链接”?“当再次单击选项卡以关闭时,如何使框按顺序恢复?”-哪个选项卡被单击(然后再次单击以关闭)?请阅读“”指南和“”页,尝试改进您的问题,以便理解并解决它。@lucasnadalutti好的,明白了。我看到3个页脚框同时弹出,我知道您希望它们一个接一个地弹出。我做对了吗?@lucasnadalutti我正试图准确地理解你的代码所产生的与预期相反的结果。实际上,我无法在这把小提琴中复制太多内容,你能修改它使其与你看到的完全一致吗?
#add
按钮在哪里?什么是“当前弹出链接”?“当再次单击选项卡以关闭时,如何使框按顺序恢复?”-哪个选项卡被单击(然后再次单击以关闭)?请阅读“”指南和“”页,尝试改进您的问题,以便理解并解决它。@lucasnadalutti好的,明白了。我看到3个页脚框同时弹出,我知道您希望它们一个接一个地弹出。我做对了吗?@lucasnadalutti我正试图准确地理解你的代码所产生的与预期相反的结果。实际上,我无法在这把小提琴中复制太多内容,你能修改它使其与你看到的完全一致吗?
#add
按钮在哪里?什么是“当前弹出链接”?“当再次单击选项卡以关闭时,如何使框按顺序恢复?”-哪个选项卡被单击(然后再次单击以关闭)?请阅读“”指南和“”页,尝试改进您的问题,以便理解并解决它。@lucasnadalutti好的,明白了。我看到3个页脚框同时弹出,我知道您希望它们一个接一个地弹出。我做对了吗?@lucasnadalutti我正试图准确地理解你的代码所产生的与预期相反的结果。实际上,我无法在这把小提琴中复制太多内容,你能修改它使其与你看到的完全一致吗?
#add
按钮在哪里?什么是“当前弹出链接”?“当再次单击选项卡以关闭时,如何使框按顺序恢复?”-哪个选项卡被单击(然后再次单击以关闭)?请看一下这本书