jQuery在固定div上滑动切换(jQuery slide toggle on a fixed div)

编程入门 行业动态 更新时间:2024-10-26 04:27:53
jQuery在固定div上滑动切换(jQuery slide toggle on a fixed div)

我在我的网站上实现了幻灯片切换功能。 单击链接将使其下方的div向上滑动到视图中。

问题是因为链接是position:fixed它不会向上移动以位于面板上方。

我希望按钮向上滑动,使其始终显示在面板上方。

在这里查看实时预览 (篮子的底角链接)

第二个问题是单击链接也会将您弹回页面顶部。 我希望用户继续使用。

<script> $(document).ready(function(){ $(".basketButton").click(function(){ $(".basket").slideToggle("slow"); }); }); </script>

CSS和HTML

<!-- Basket overlay --> <div class="basketButton"> <a href="">Your Shopping Bag</a> </div> <div class="basket"> <h3>Your Shopping Bag</h3> </div> /* Basket */ .basketButton{ position:fixed; bottom:25px; right:25px; background-image:url('images/pinkbag.png'); padding-left:60px; display:inline-block; background-repeat: no-repeat; height: 67px; } .basketButton a{ font-weight:bold; font-size:18px; color: #67062F; padding-top:15px; display:inline-block; } .basket{ display:none; width:250px; height:200px; padding:10px; border-radius:5px; position:fixed; bottom:25px; right:25px; background-image:url('images/pink-bg.png'); } .basket h3{ color:#FFF; }

的jsfiddle

I've implemented a slide toggle function on my site. Click a link will cause the div below it to slide up into view.

The problem is that because the link is position:fixed it does not move up to sit above the panel.

I'd like the button to slide up so that it always appears above the panel.

See live preview here (bottom corner link for basket)

A second issue is that clicking the link also bounces you to the top of the page. I'd like the user to remain put.

<script> $(document).ready(function(){ $(".basketButton").click(function(){ $(".basket").slideToggle("slow"); }); }); </script>

CSS & HTML

<!-- Basket overlay --> <div class="basketButton"> <a href="">Your Shopping Bag</a> </div> <div class="basket"> <h3>Your Shopping Bag</h3> </div> /* Basket */ .basketButton{ position:fixed; bottom:25px; right:25px; background-image:url('images/pinkbag.png'); padding-left:60px; display:inline-block; background-repeat: no-repeat; height: 67px; } .basketButton a{ font-weight:bold; font-size:18px; color: #67062F; padding-top:15px; display:inline-block; } .basket{ display:none; width:250px; height:200px; padding:10px; border-radius:5px; position:fixed; bottom:25px; right:25px; background-image:url('images/pink-bg.png'); } .basket h3{ color:#FFF; }

JSFiddle

最满意答案

只需添加return false :

<script> $(document).ready(function(){ $(".basketButton").click(function(){ $(".basket").slideToggle("slow"); return false; }); }); </script>

链接尝试导航到锚点#,这是页面的顶部。 返回false将禁用链接的默认行为。

对于定位,只需使用一个固定的div与按钮和篮子里面: http : //jsfiddle.net/w1ll3m/9fZsj/3/

Just add return false:

<script> $(document).ready(function(){ $(".basketButton").click(function(){ $(".basket").slideToggle("slow"); return false; }); }); </script>

The link tries to navigate to the anchor #, and that's the top of the page. Return false disables the default behavior of the link.

For the positioning just use one fixed div with the button and the basket inside: http://jsfiddle.net/w1ll3m/9fZsj/3/

更多推荐

本文发布于:2023-08-04 11:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1414851.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:div   jQuery   slide   fixed   toggle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!