简体   繁体   English

将css悬停转换为jquery onclick for div layer

[英]convert css hover to jquery onclick for div layer

We have a header, with username on it. 我们有一个标题,上面有用户名。 Essentially, for now, the user hovers over there username and precariously moves the mouse onto the div to retain focus, and access different account functionality. 基本上,就目前而言,用户在那里悬停用户名并且不稳定地将鼠标移动到div上以保持焦点,并访问不同的帐户功能。

But it is crap to be honest, and I wanted to convert it to onclick, ala google style. 但说实话,这是废话,我想把它转换为onclick,ala google风格。

Here is a screenpic of what we have. 这是我们所拥有的一个画面。

在此输入图像描述

Here is what I would like to achieve. 这就是我想要实现的目标。

在此输入图像描述

Wondering if anyone knows how to do this. 想知道是否有人知道如何做到这一点。

Sample fiddle here: http://jsfiddle.net/ozzy/WkLBF/ 示例小提琴: http//jsfiddle.net/ozzy/WkLBF/

Essentially, I want it so user clicks on the name and the div panel displays and remains until they click again. 基本上,我想要它,所以用户点击名称和div面板显示并保持,直到他们再次点击。

Any help appreciated, we use jquery if thats any consolation ( this demo uses no javascript at all at present ) 任何帮助,我们使用jquery,如果这是任何安慰(这个演示目前根本不使用javascript)

Well... this will work as far as you have described, but I'm not sure it's exactly what you want. 嗯......这可以就你所描述的那样奏效,但我不确定这正是你想要的。 :P Could you expound? :你能解释一下吗?

Demo 演示

$(".category-filter>li").click(function(){
    $(this).children("ul").toggle();
});

http://jsfiddle.net/WkLBF/25/ http://jsfiddle.net/WkLBF/25/

Javascript: 使用Javascript:

jQuery(document).ready(function($){
    $('ul li a').live('click', function(){
        if($('.category-filter>li:hover>ul').css('display')=='none')
        {
            $('.category-filter>li:hover>ul').css('display', 'block');
            $(this).addClass('userbox-on');
        }
        else
        {
            $('.category-filter>li:hover>ul').css('display', 'none');
            $(this).removeClass('userbox-on');
        }
    });
});

CSS: CSS:

.userbox-on
{
  border: 1px solid red;
  border-bottom: none;  
  background-color: #fff;
    padding: 5px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM