简体   繁体   English

滑动面板位于内容下方?

[英]Sliding Panels sitting underneath content?

This is a follow up on a previous question...I was helped out by Marcatectura (thanks again!) , and this is the example they gave me: http://jsfiddle.net/rt9d5/10/embedded/result/ 这是上一个问题的后续……Marcatectura帮助了我(再次感谢!),这是他们给我的示例: http : //jsfiddle.net/rt9d5/10/embedded/result/

I decided to change the 'li' elements to 'div' elements, as it works better for my intended design. 我决定将“ li”元素更改为“ div”元素,因为它可以更好地用于我的预期设计。 But as I'm not that well versed in jquery I've done something wrong in trying to get mine to look the same. 但是由于我对jQuery不太了解,所以在尝试使我看起来相同时做错了什么。 http://fiddle.jshell.net/faedince/L4L4N/ (Here's a little bit of my code.) http://fiddle.jshell.net/faedince/L4L4N/ (以下是我的代码的一部分。)

#panelOne:after {
    display: block;
    background: red;
    opacity: 0.9;
    width: 350px;
    height: 350px;
    content: "";

    -webkit-transition: -webkit-transform 500ms ease-out 0s;
    -moz-transition: -moz-transform 500ms ease-out 0s;
    -o-transition: -o-transform 500ms ease-out 0s;
    transition: transform 500ms ease-out 0s;


$( '#panelOne' ).click(function(){
    $( '#panelOne' ).removeClass( 'clicked' );
    $(this).addClass( 'clicked' );
}); 

The red covers are sitting underneath the white panels, and are too far down the page. 红色的盖板位于白色的面板下方,距离页面太远。 As per the example they're supposed to be on top of the white panels. 根据示例,它们应该位于白板的顶部。 Could someone tell me what I'm doing wrong please? 有人可以告诉我我在做什么错吗?

It looks like you need to add position: absolute to your :after classes (along with the top and left positioning). 看来您需要在:after类中添加position: absolute (以及topleft位置)。 You can also get away with simplifying your JS a bit. 您也可以通过简化JS摆脱困境。 Instead of trying to code for every possible click combination, make one bit of code that can apply to all of them. 不必尝试为每种可能的点击组合编写代码,而是编写一点代码即可应用于所有这些代码。

Demo Fiddle 演示小提琴

CSS: you can replace all of your individual :after css calls with the following. CSS:您可以将CSS调用:after所有个人:after替换为以下内容。

.bigbox > div:after {
    content: "";
    position: absolute;
    top: 0px;
    left: 0px;
    display: block;
    background: red;
    opacity: 0.9;
    width: 350px;
    height: 350px;

    -webkit-transition: -webkit-transform 500ms ease-out 0s;
    -moz-transition: -moz-transform 500ms ease-out 0s;
    -o-transition: -o-transform 500ms ease-out 0s;
    transition: transform 500ms ease-out 0s;
}

JS: JS:

$('.bigbox div').on('click', function(){
    $('.bigbox div').removeClass('clicked');
    $(this).addClass('clicked');
});

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

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