jquery - css jquery 菜单 - 切换幻灯片放映隐藏 div

标签 jquery html css ipad

checkout 码here !

这些是我的问题:

  1. Div 不会在单击自身时切换为隐藏,只有在我单击另一个时才会隐藏。 (编辑:或基本上任何地方)

  2. 所有应该隐藏的 div 在页面加载时闪烁然后消失。有什么办法可以避免吗? (解决了!css display:none;)

  3. 被点击的 div 应保持其突出显示的背景颜色,直到其他人或自己被点击。想不通。

  4. (侧面)当我在 ipad 上打开页面时,menu_row 在单击时保持其 :hover 背景色。没关系,但是当单击 self 并且显示的 div 缩回时,它应该恢复为灰色。可能吗?

最佳答案

1.

jQuery(document).ready(function($) {

    //cache the `.menuImage` elements since they will be used frequently
    var $menuImages = $(".menuImage").hide('slow');
    $(".menuItem").click(function() {

        //get the `.menuImage` element that is a child of the clicked element
        var $ele = $(this).children(".menuImage");

        //`.slideUp()` all the `.menuImage` elements that aren't a child of the clicked element
        $menuImages.not($ele).slideUp(500);

        //toggle the visibility of the child of the clicked element
        $ele.slideToggle(500);
    });
});​

演示:http://jsfiddle.net/jasper/XcJwW/17/

3.

jQuery(document).ready(function($) {
    var $menuImages = $(".menuImage").hide('slow');
    $(".menuItem").click(function() {
        var $ele = $(this).children(".menuImage");

        //not only slide the rest of the `.menuImage` elements away, but also remove the `hover` class from them
        $menuImages.not($ele).slideUp(500).parent().removeClass('hover');

        //not only toggle the view of the clicked `.menuImage` element, but also toggle the `hover` class for the element
        $ele.slideToggle(500).parent().toggleClass('hover');
    });
});​

这需要对您的 CSS 进行一些小的调整:

#menu_row1 .menuItem:hover, #menu_row1 .menuItem.hover { background:#ff0000; }
#menu_row2 .menuItem:hover, #menu_row2 .menuItem.hover { background:#ffe100; }
#menu_row3 .menuItem:hover, #menu_row3 .menuItem.hover { background:#0033cc; }

请注意,用户可以悬停这些元素之一,或者您可以为该元素提供hover类,两者都会产生相同的结果。

演示:http://jsfiddle.net/jasper/XcJwW/20/

关于jquery - css jquery 菜单 - 切换幻灯片放映隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9471046/

相关文章:

javascript - 如果按下所有必需的键,则调用带有参数的函数

javascript - 加载我所有的图像只包含在一个 DIV 中

html - Clearfix 无法处理包含视频的 div

html - SVG <a> 元素内的 <text> 元素在 IE 中没有下划线

javascript - 如何在html页面运行时默认显示模态

javascript - 如果我使用 appendChild() 或 jQuery.append(),动态加载 JavaScript 文件是不同的

php - 为什么这个脚本要加一个问号?

javascript - 如何用 jquery 或替代方法隐藏一个 div?

html - CSS 中的 no-drop 和 not-allowed 有什么区别?

css - Visual Studio 2015 转到缺少 CSS 类的定义