动画 div...无法让它停止推送所有 div (Magento)
解释起来有点困难,但就这样吧。我有一个 div,它使用 jquery 使用切换来动画它的高度。基本上,div 最初是隐藏的,但如果您按下按钮,它会扩展 css 中定义的高度。这是 js:
jQuery(document).ready(function() { jQuery('.slidedown').hide(); jQuery("button").click(function() { jQuery('.slidedown').animate({ height: ['toggle', 'swing'], }, 500, function() { }); }); });
所以我有一个带有“slidedown”类的 div。按下按钮,它向下展开。然而,当 div 动画时,它也会将我页面上的所有其他 div 向下推。我只想展开 div,但要查看页面上的其他所有内容。我想要实现的实际上是 Magento 中的下拉式购物车显示,您将鼠标悬停在标题中的“购物车”一词上,然后购物车的内容出现在显示的 div 中。我通过以下方式使购物车内容显示在 div 中:
<div class="slidedown"><?php echo $this->getChildHtml('right') ?></div></pre>
调用 getChildHtml('right') 将购物车内容插入到 div 中。效果很好。到目前为止,我只尝试将该 div 放在 2columns-left.phtml 模板中的各个位置,我的所有页面都在 Magento 中使用该模板。但在我尝试插入该 div 的任何地方,当它展开时,它都会弄乱所有其他内容。有什么想法吗?感谢您的意见。
It's a bit hard to explain but here goes. I have a div that uses jquery to animate it's height using toggle. Basically the div is initially hidden but if you press a button it expands the height defined in the css. Here's the js:
jQuery(document).ready(function() { jQuery('.slidedown').hide(); jQuery("button").click(function() { jQuery('.slidedown').animate({ height: ['toggle', 'swing'], }, 500, function() { }); }); });
So i have a div with class "slidedown". Press the button and it expands downwards. However when the div animates it pushes all the other divs on my page down too. I just want the div to expand but go over everything else on the page. What i'm trying to achieve is actually a drop down shopping cart display in Magento, you mouse over the word 'shopping cart' which is in the header and then the cart's contents appear in the div that is revealed. I make the cart contents appear in the div by:
<div class="slidedown"><?php echo $this->getChildHtml('right') ?></div></pre>
Calling getChildHtml('right') inserts the cart contents into the div. That works fine. So far i have only tried putting that div in various locations in the the 2columns-left.phtml template that all my pages are using in Magento. But anywhere i try to insert that div, when it expands it messes up all the others. Any ideas? Thanks for your input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以做到这一点,要么使其绝对定位。 ——说实话,我不建议这样做。
我认为更好的方法是添加一个父 div 并将其高度设置为 0:
HTML:
CSS:
这样您就可以向购物车添加某种遮罩,因此无论它有多大,浏览器都会查看其父级 div,发现其高度为 0,并且不会推送任何其他 HTML 元素。
PS 可能会出现问题,购物车将显示在其他元素下方,要修复此问题,只需将此 CSS 添加到
.mask-layer
:.mask-layer {height:0;overflow :visible;position:relative;z-index:2 /* 或任何数字,只要它大于其他元素的 z-index*/}
There are several ways to do it, either make it absolute positioned. -- To be honest, I don't suggest that.
A better way in my opinion is to add a parent div and give it a height of 0:
HTML:
CSS:
This way you would add some kind of a mask to your shopping cart, so no matter how big it is, the browser will look at its parent div and see that it has a height of 0 and will not push any other HTML element.
P.S. A problem might occur, where the cart will be shown below your other elements, to fix it just add this CSS to
.mask-layer
:.mask-layer {height:0;overflow:visible;position:relative;z-index:2 /* or any number as long as it is larger than the z-index of your other elements*/}