LavaLamp - 在为多个页面使用模板时设置“当前”

时间:2012-04-29 16:46:29

标签: jquery lavalamp

我在我们网站(家庭,博客,论坛,图库,教程和常见问题解答)中的几个或我们的页面使用vBulletin,目前正在使用lavalamp(http://www.gmarwaha.com/blog/2007/08/ 23 / LavaLamp的换的jquery爱好者/).

几周以来,我一直在努力尝试动态设置“当前”类,这取决于您所在的页面。下面是我失败尝试的几个例子 - 我已经验证了代码的工作原理,因为我能够找到正确的li ..但addClass或removeClass,只是不起作用。我已经尝试使用菜单的ID作为选择器,将脚本放在几个不同的位置,使其成为一个函数并使用lavalamp inialization代码调用该函数...任何帮助将不胜感激!

首次尝试:

<!--BEGIN LAVA MENU-->
    <ul class="lavaLamp" id="lavaMM">
        <li><a href="/">Home</a></li>
        <li><a href="/market/">Market</a></li>
        <li><a href="/content.php/475-the-daily-buzz">Blog</a></li>
        <li><a href="/forum/forum.php">Forum</a></li>
        <li><a href="/gallery/">Gallery</a></li>
        <li><a href="/forum/forumdisplay.php/439-Scrap-Orchard-University">Tutorials</a></li>
        <li><a href="/staff/">Staff</a></li>
        <li><a href="/forum/faq.php">FAQ</a></li>
        <li><a href="/market/support/">Support</a></li>
    </ul>
<!--END LAVA MENU-->


<script language="javascript" type="text/javascript">
$(document).ready(function(){
    $('#lavaMM').lavaLamp({
        fx: 'backout', 
        speed: 700,
        click: function(event, menuItem) {
            return true;
        }
    });
    var fullURL = document.URL;
    var splitURL = fullURL.split('/', 4);
    if (splitURL[3] == 'content.php') {
        $('ul.lavaLamp li:eq(2)').addClass('current');
    }
    else if (splitURL[3] == 'forum') {
            $('ul.lavaLamp li:eq(3)').addClass('current');
    } 
    else if (splitURL[3] == 'gallery') {
            $('ul.lavaLamp li:eq(4)').addClass('current');
    } 
});
</script>

第二次尝试:

<!--BEGIN LAVA MENU-->
    <ul class="lavaLamp" id="lavaMM">
        <li><a href="/">Home</a></li>
        <li><a href="/market/">Market</a></li>
        <li class="current"><a href="/content.php/475-the-daily-buzz">Blog</a></li>
        <li class="current"><a href="/forum/forum.php">Forum</a></li>
        <li class="current"><a href="/gallery/">Gallery</a></li>
        <li><a href="/forum/forumdisplay.php/439-Scrap-Orchard-University">Tutorials</a></li>
        <li><a href="/staff/">Staff</a></li>
        <li><a href="/forum/faq.php">FAQ</a></li>
        <li><a href="/market/support/">Support</a></li>
    </ul>
<!--END LAVA MENU-->

<script language="javascript" type="text/javascript">
$(document).ready(function(){
    $('#lavaMM').lavaLamp({
        fx: 'backout', 
        speed: 700,
        click: function(event, menuItem) {
            return true;
        }
    });
    var fullURL = document.URL;
    var splitURL = fullURL.split('/', 4);
    if (splitURL[3] == 'content.php') {
        $('ul.lavaLamp li:eq(3)').removeClass('current');
        $('ul.lavaLamp li:eq(4)').removeClass('current');
    }
    else if (splitURL[3] == 'forum') {
            $('ul.lavaLamp li:eq(2)').removeClass('current');
        $('ul.lavaLamp li:eq(4)').removeClass('current');
    } 
    else if (splitURL[3] == 'gallery') {
        $('ul.lavaLamp li:eq(2)').removeClass('current');
            $('ul.lavaLamp li:eq(3)').removeClass('current');
    } 
});
</script>

第三次尝试:

<!--BEGIN LAVA MENU-->
    <ul class="lavaLamp" id="lavaMM">
        <li><a href="/">Home</a></li>
        <li><a href="/market/">Market</a></li>
        <li><a href="/content.php/475-the-daily-buzz">Blog</a></li>
        <li><a href="/forum/forum.php">Forum</a></li>
        <li><a href="/gallery/">Gallery</a></li>
        <li><a href="/forum/forumdisplay.php/439-Scrap-Orchard-University">Tutorials</a></li>
        <li><a href="/staff/">Staff</a></li>
        <li><a href="/forum/faq.php">FAQ</a></li>
        <li><a href="/market/support/">Support</a></li>
    </ul>
<!--END LAVA MENU-->



<script language="javascript" type="text/javascript">
$(document).ready(function(){
    var fullURL = document.URL;
    var splitURL = fullURL.split('/', 4);
    if (splitURL[3] == 'content.php') {
        $('ul.lavaLamp li:eq(2)').each(function() {
                    $(this).addClass('current');
        });
    }
    else if (splitURL[3] == 'forum') {
            $('ul.lavaLamp li:eq(3)').each(function() {
                    $(this).addClass('current');
            });
    } 
    else if (splitURL[3] == 'gallery') {
            $('ul.lavaLamp li:eq(4)').each(function() {
                    $(this).addClass('current');
            });
    } 
});
</script>

1 个答案:

答案 0 :(得分:0)

在文件lavalamp.js中 将o替换为:

o = $.extend({ fx: "linear", speed: 500, classes: 'current', click: function(){} }, o || {});
$current = o.classes;

调用函数:

 $(function() { $("#menu_main").lavaLamp({ fx: "backout", speed: 700 ,classes : 'current_page_item'})});