jQuery:多个当前夸大的问题

标签 jquery css jquery-ui jquery-ui-tabs

我想自定义 jQuery 脚本,以便在单击 3 个不同选项卡中的 1 个时识别不同的“当前”状态。目前,代码只允许识别一种“当前”状态,因此当我单击不同的选项卡时,会显示按钮的相同夸大状态。我已经仔细检查了我的代码好几个小时,现在我不同意您的专业知识来寻求帮助。

可能的解决方案?: 添加某种 ID 监听器,识别当前状态显示为夸大状态。

HTML 片段:

<ul class="nav">
<li><a href="#"><img src="textSpacer.png" width="87" height="20"></a>
  <ul>
    <img src="subContentSearch.gif">
    </ul>
</li>
<li><a href="#"><img src="textSpacer.png" width="84" height="20"></a>
    <ul>
    <img src="subContentNewsSignUp.gif">
    </ul>
</li>
<li><a href="#"><img src="textSpacer.png" width="100" height="20"></a>
    <ul>
    <img src="subContentMyVictory.gif">
    </ul>
</li>

jQuery.Clickme.js:

(function($) {

$.fn.clickMe = function(op_user) {

    var menuName = this,                
        op = $.extend( cm.op_default , op_user);

    $(menuName).find("li:has(ul)").addClass("arrow");
    // move content to inicial margin
    $(op.moveIt).css({ marginTop: op.moveItMargin });

    //  anchor inside menu active the code
    $(menuName).find("a").click(function() {

        var ulsVisible = $(menuName).find("ul").is(":visible");
        var testUl = $(this).next("ul").is(":visible");

        // hide and remove op.activeMenu class from visible list inside the menu 
        if (ulsVisible) {
            // know if the anchor that active the function is visible
            if(testUl) {                    
                $(menuName).find("li").removeClass(op.activeMenu);
                moveContent(); 
                $(this).next("ul").animate(op.aniHide, op.speed);           
            } else {
                $(menuName).find("li").removeClass(op.activeMenu);                      
                $(menuName).find("ul").animate(op.aniHide, op.speed);
                $(this).parent("li").addClass(op.activeMenu);
                 moveContent();
                $(this).next("ul").animate(op.aniShow, op.speed );
            }
        } else {
            $(this).parent("li").addClass(op.activeMenu);
            moveContent();
            $(this).next("ul").animate( op.aniShow, op.speed);          
        }
    });

    // Move content 
    function moveContent() {

        var ulHeight = $("."+op.activeMenu +" ul").height() ;
        var moveMargin = parseFloat($(op.moveIt).css("margin-top"));
        var dif = ulHeight + op.moveItMargin - moveMargin;                  

        if (ulHeight == moveMargin) {

        } else if (ulHeight < moveMargin) {
            $(op.moveIt).animate({marginTop: "+=" + dif}, op.speed);

        } else if (ulHeight > moveMargin){
            $(op.moveIt).animate({marginTop: "+=" + dif}, op.speed);            

        }                                           
    }

};

var cm = $.fn.clickMe;
cm.op = {};
cm.op_default = {
    activeMenu: "current",
    moveIt: ".content",
    moveItMargin : 0,
    aniShow: { opacity: "show", height: "show"},
    aniHide: { opacity: "hide", height: "hide"},
    speed: "fast"
};

})(jQuery);

正在使用的 CSS 代码段: .current {背景颜色:#D1EFEF;} .current a {颜色:#FFF;背景图像:url(“siteSearch_down.gif”);} .current a:hover {color: #000;}


我衷心感谢您的时间和帮助。

最佳答案

在黑暗中拍摄,但也许在外部范围内设置状态之类的事情可以帮助你..

var fnc, state = 'state1';
fnc = function () {
  if (state === 'state1') {
    // do something 
    // update the state
    state = 'state2';
  }
  // ... etc
};<p></p>

<p></p>

关于jQuery:多个当前夸大的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4293282/

相关文章:

javascript - 鼠标滚轮事件不适用于 Firefox

javascript - 具有 "this"变量的抽象

php - 加载图像花费太多时间

javascript - 功能的禁用/启用按钮不起作用

html - 停止覆盖以前的 CSS 属性

css - 以编程方式更新字段时如何删除自动填充突出显示?

javascript - 带有 _renderItem 和类别的 jQuery 自动完成

jquery - 当一个 div 使用 jquery 加载图像时,它里面的其他 div 正在消失。为什么会发生这种情况?

javascript - 未提交 JQuery Datepicker 值

javascript - 无法从 Shopify 调用 instagram API