简体   繁体   English

将DIV移出屏幕而不会弄乱宽度?

[英]Move DIV off screen without messing with width?

I have an eCommerce cart I am working on, and when a button is clicked, the cart slides out from the left of the screen. 我有一个正在处理的电子商务购物车,当点击一个按钮时,购物车从屏幕左侧滑出。 I have that part working fine. 我有那部分工作正常。

<section class="ec-cart">
    <h3>Cart</h3>
</section>

<div class="main-content">
    <div class="overlay-wrap"></div>
    <p>Text text text</p>
    <a class="cart-btn" href="#">Your Cart</a>
</div>

When the .cart-btn link is clicked, the .ec-cart slides out fine, but the .main-content does not slide off of the screen like I need it to. 单击.cart-btn链接时, .ec-cart滑出,但.main-content不会像我需要的那样滑出屏幕。 I need it to KEEP THE SAME WIDTH, and just slide off the screen to the right the same amount as the width of the cart. 我需要它保持相同的宽度,然后从屏幕向右滑动与购物车宽度相同的数量。

This JS Fiddle example shows what I have: http://jsfiddle.net/RNmaq/ 这个JS小提琴示例显示了我的内容: http//jsfiddle.net/RNmaq/

As seen in the JSFiddle example above, the width of the container shrinks when the cart comes into view. 如上面的JSFiddle示例所示,当推车进入视图时,容器的宽度会缩小。

This website shows what I am going for. 这个网站显示了我的目标。 If you click the cart button in the top right: http://bit.ly/1gJiy1a 如果单击右上角的购物车按钮: http//bit.ly/1gJiy1a

I am achieving the effects thus far by toggling classes. 到目前为止,我通过切换课程来实现这些效果。 I am open to other suggestions if there is an easier way to do this. 如果有更简单的方法,我愿意接受其他建议。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Set the Width of the main-content to 100% 将主要内容的宽度设置为100%

.main-content {
    transition:left .5s;
    background:#f1f1f1;
    width:100%;
}

here is a fiddle http://jsfiddle.net/RNmaq/4/ 这是一个小提琴http://jsfiddle.net/RNmaq/4/

Setting the width of .main-content to 100% like this: .main-content的宽度设置为100%如下所示:

.main-content {
    transition:left .5s;
    background:#f1f1f1;
    width: 100%;
}

fixes it. 解决它。 See fiddle 看小提琴

you could use the CSS3 transform:translateX(); 你可以使用CSS3 transform:translateX(); style 样式

.main-content {
    transition:all .5s;
    background:#f1f1f1;
}
.main-content-dis {
    position:fixed;
    -moz-transform: translateX(30%);
    -webkit-transform: translateX(30%);
    -o-transform: translateX(30%);
    -ms-transform: translateX(30%);
    transform: translateX(30%);
}

http://jsfiddle.net/RNmaq/6/ http://jsfiddle.net/RNmaq/6/

similarly if you could apply the translateX to your cart section so that they transition nicely timed together: 同样,如果你可以将translateX应用到你的购物车部分,以便他们可以很好地定时转换:

.ec-cart {
    width:30%;
    position:fixed;
    -moz-transform: translateX(-100%);
    -webkit-transform: translateX(-100%);
    -o-transform: translateX(-100%);
    -ms-transform: translateX(-100%);
    transform: translateX(-100%);
    height:100%;
    z-index:5000;
    background:#f1f1f1;
    transition:all .5s;
}
.ec-cart-active {
    -moz-transform: translateX(0);
    -webkit-transform: translateX(0);
    -o-transform: translateX(0);
    -ms-transform: translateX(0);
    transform: translateX(0);
}

fiddle for both using translateX : http://jsfiddle.net/RNmaq/7/ 使用translateX小提琴: http//jsfiddle.net/RNmaq/7/

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

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