0

这件事按预期工作。是一个演示。

<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js'></script>

                <script>
                $(window).load(function() {
                      $('#about, #subscribe, #contact').hide();

                      $('.home').click(function() {
                        var id = $(this).html().toLowerCase();
                        var $content = $('#' + id + ':not(:visible)');
                        if ($('.current').length === 0) {
                            showContent($content)
                        }
                        else {
                            $('.current').fadeOut(600, function() {
                                showContent($content)
                            });
                        }
                    });

                    function showContent(content) {
                        content.fadeIn(600);
                        $('.current').removeClass('current');
                        content.addClass('current');
                    } 
                  });
                </script>

                    <div id="nav">
                        <a class="home" id="show_about" title="About">ABOUT</a><br />
                        <a class="home" id="show_subscribe" title="Subscribe">SUBSCRIBE</a><br/>
                        <a class="home" id="show_contact" title="Contact">CONTACT</a>
                    </div>
                    <div id="content">
                        <div class="current" id="about">
                            <p>ABOUT's content</p>
                        </div>
                        <div id="subscribe">
                            <p>SUBSCRIBE's content</p>
                        </div>
                        <div id="contact">
                            <p>CONTACT's content</p> 
                        </div>
                    </div>

我想用图像替换文本(关于、订阅和联系)。所以我尝试了这个,但它不起作用..你知道为什么吗?:)

4

3 回答 3

0

The first error i see here is in console:

GET http://gioiellidisapone.it/http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.map 404 (Not Found)

<script type="text/rocketscript" data-rocketsrc="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js" data-rocketoptimized="true"></script>
<script type="text/rocketscript" data-rocketsrc="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js" data-rocketoptimized="true"></script>

you lacked http: on the above line

于 2013-08-25T17:48:32.477 回答
0

尝试使用这个:

$('#about, #subscribe, #contact').hide();

$('.home').click(function () {
    var id = this.id.replace('show_', ''); // this line has been changed
    var $content = $('#' + id + ':not(:visible)');
    if ($('.current').length === 0) {
        showContent($content)
    } else {
        $('.current').fadeOut(600, function () {
            showContent($content)
        });
    }
});

function showContent(content) {
    content.fadeIn(600);
    $('.current').removeClass('current');
    content.addClass('current');
}

当您单击一个链接时,它会使用该链接,id然后删除show_并显示带有该链接的 div id。这是一个例子:

用户单击顶部链接。idshow_about。_ javascript删除show_离开,about然后选择$('#about:not(:visible)');并淡入。

它在这里工作:http: //jsfiddle.net/dVrV9/

于 2013-08-25T17:46:33.830 回答
0
<script>
                $(window).load(function() {
                      $('#about, #subscribe, #contact').hide();

                      $('.home').click(function() {
                        //var id = $(this).html().toLowerCase();
                        //var $content = $('#' + id + ':not(:visible)');
                        var $content = $('#' + $(this).attr('title').toLowerCase() + ':not(:visible)');  // changed Here..
                        if ($('.current').length === 0) {
                            showContent($content)
                        }
                        else {
                            $('.current').fadeOut(600, function() {
                                showContent($content)
                            });
                        }
                    });

                    function showContent(content) {
                        content.fadeIn(600);
                        $('.current').removeClass('current');
                        content.addClass('current');
                    } 
                  });
                </script>

您将图像作为内容..

您必须改为获取 Title 属性。

于 2013-08-25T17:50:21.767 回答