jQuery/CSS : showing a div at the bottom of ages causes scroll bar and you can't see the div

标签 jquery html css

我想在我的网站底部添加一个显示和隐藏 div 的按钮。当您单击按钮时,div 会显示出来,但它会创建额外的滚动空间,您看不到 div。这里的例子

http://jsfiddle.net/G2Fqe/ (如果你滚动到按钮并点击蓝色按钮

当我将 div 放在菜单栏顶部时,会发生同样的事情。有没有办法将视口(viewport)与新的 div 对齐?或者我不知道的东西?非常感谢您的帮助

最佳答案

试试这个:

    $(function(){

         $("div.button1-content").hide();

            $('a#button1').click(function(){
                $('div.button1-content').toggle(0, function() {
                    $('html, body').animate({scrollTop: $('div.button1-content').offset().top - $('div.button1-content').height() + 'px'}, 200);  
                });
            });
   }); 

您需要对此进行调整,以便在隐藏该 div 后它可以正确滚动,但我认为这就是您正在寻找的一般想法。

关于jQuery/CSS : showing a div at the bottom of ages causes scroll bar and you can't see the div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8528823/

相关文章:

javascript - 通过激活交通灯按钮手动切换灯

javascript - 如何限制一个div可以包含的元素? HTML

javascript - 如何选择特定元素后面的元素的所有内容?

javascript - JS/CSS Accordion 滑动过渡问题

javascript - jQuery 在 ajax 调用中选择附加元素不起作用

javascript - 使用 jquery 覆盖 anchor 标记的默认行为

html - 横向滚动时浏览器不展开内容?

javascript - 在Gmail上,为什么不能用javascript点击 "To"字段?

html - 如何使用CSS改变图标颜色

Jquery - 将 css 样式应用于指定 div 中的所有元素?