简体   繁体   English

在页脚上使用slidetoggle时,如何从顶部推入所有元素?

[英]How can I push all elements from the top when I use slidetoggle on the footer?

I have a footer, and when this one is clicked I want it to slide toggle up and push all the elements from the top without overlapping them. 我有一个页脚,当单击该页脚时,我希望它向上滑动并从顶部推入所有元素而不重叠它们。

This is the first view 这是第一个视图 在此处输入图片说明

And this is the view after clicking the yellow element 这是单击黄色元素后的视图

在此处输入图片说明

I was not able to reproduce this on jsfiddle. 我无法在jsfiddle上重现此内容。 Here is my css, my js and my bottom html 这是我的CSS,我的js和我的底部html

$("li#dropdown").on('click', function(e) {
    $('#toggleList').slideToggle();
    e.preventDefault();
});

Here is my bottom CSS, using LESS 这是我的基本CSS,使用LESS

footer {
    background-color: #F8F8F8;
    text-align: center;
    padding-top:36px;
    position: absolute;
    width: 100%;
    bottom: 0;
    display:inline-block;
    nav {
        //margin-top:36px;
        ul {
            list-style-type: none;
            margin:0;
            padding:0;
            text-align: center;
            li {
                display:inline-block;
                a {
                    text-decoration: none;
                    font: normal 16px "proxima_novasemibold", helvetica;
                    color: #828282;
                    padding:0 8px;
                    margin-left: 5px;
                    &:hover {
                        text-decoration: none;
                        color: @pale-green;
                    }
                }
                &#dropdown {
                    cursor: pointer;
                }
            }
            li:last-child a span {
                background:url(../img/arrow.jpg) no-repeat;    
                width:16px;
                height:12px;
                display:inline-block;
                margin-left: 5px;
            }
        }
        .franchise-list {
            text-align: justify;
            display: inline-block;
            margin:23px 0;
            h4 {
                text-transform: uppercase;
                margin:5px 0;
                font-size: 12px;
                font-weight: bold;
                color: #666;                    
            }
            span {

            }
            .franchise-col {
                float:left;
                font-size: 11px;
                margin-left:20px;
            }
        }
    }
    .bottom-info {
        font: normal 12px "proxima_novasemibold", helvetica;
        padding-top: 26px;
        padding-bottom: 18px;
        background-color: #F8F8F8;
        text-align: center;
        span {
            color:#696969;
        }
        div {
            display:inline;
            color: #199151;
            a {
                color:#199151;
                text-decoration: underline;
            }
        }
    }  
}  

And Here is my bottom HTML 这是我的底部HTML

<footer>
<nav>
    <ul>
        <li><a href="">ABOUT APPLE AUTO GLASS</a></li>
        <li><a href="">SIX POINT CARE PROCESS&#8482;</a></li>
        <li><a href="">HASSLE FREE INSURANCE CLAIMS</a></li>
        <li><a href="">FAQ</a></li>
        <li id="dropdown"><a>APPLE AUTO GLASS STORES<span class="dropdown-stores"></span></a></li>
    </ul>  
    <div class="franchise-list" id="toggleList" style="display:none;">   
    <?php 
        $regions = [];
        $listFranchises = [];
    ?>
@foreach($franchises as $key => $value)            
        <?php 
            $listFranchises[$key] = [$value->region, $value->town, $value->address];
            if (!(in_array($value->region, $regions))) {
                array_push($regions, $value->region);
            }                                     
        ?>
@endforeach
    <?php
        $counter = 0;
        $franchiseList = count($listFranchises) + count($regions);
        $marker = true;
        foreach($regions as $region) {           
            if ($counter%14 === 0 && $marker) {
                echo ('<div class="franchise-col">');             
            }
            else {
                $marker = true;
            }
            $counter += 1;
            echo ('<h4 counter="'.$counter.'/'.$franchiseList.'">'.$region.'</h4>');               
            foreach($listFranchises as $key => $value) {                  
                if($region === $value[0]) {
                    $counter += 1;
                    echo ('<span counter="'.$counter.'/'.$franchiseList.'"><a href="#">'.$value[1].'</a> - '.$value[2].'</span><br>');
                    if ($counter%14 === 0) {
                        echo ('</div>');
                    }
                    if ($counter%14 === 0 && ($franchiseList-$counter > 0)) {
                        echo ('<div class="franchise-col">'); 
                        $marker = false;
                    }
                    if (($franchiseList - $counter) == 0) {
                        echo ('</div>');
                    }
                } 
            }                 
        }
    ?>  

    </div>
</nav>
<div class="bottom-info">
    <span>Copyright &#169; <?php echo date('Y') ?> Apple Auto Glass &#174;. All Rights Reserved.</span>
    <div>
        <a href="">Terms of Use</a> |
        <a href="">Privacy Policy</a>
    </a>
</div>   

Here's one way, not optimized or cleaned up at all, but it works: 这是一种方法,根本没有进行优化或清理,但是可以起作用:

http://jsfiddle.net/b6rkb/40/ http://jsfiddle.net/b6rkb/40/

$(document).ready(function () {
    var panelHeight = $("#panel").show().height(),
        docHeight = $(document).height(),
        panelToggle = false,
        maxTopOffset = $(".page").offset().top + $(".page").outerHeight();
    $("#panel").css("height","0px");
    $("#flip").click(function () {
        var targetHeight;
        if (panelToggle) {
            targetHeight = 0;
        } else {
            targetHeight = panelHeight;   
        }
        panelToggle = !panelToggle;
        $("#panel").finish().animate({
            height: targetHeight   
        },{
            step: function(height) {
                if (panelToggle) {
                    var distance = maxTopOffset - $(".footer").offset().top;                
                    if (distance > -10) {
                        $(".footer").css("position","relative");
                    }
                } else {
                    console.log(docHeight,$(document).height())
                    if ($(document).height() == docHeight) {
                        $(".footer").css("position","absolute");
                    }                    
                }

            },
            duration: 500
        });
    });
});

It uses two different techniques. 它使用两种不同的技术。

When opening the panel, i check the distance between the top of the panel and the bottom of the page. 打开面板时,我检查面板顶部和页面底部之间的距离。 When it is 10px from the bottom or less, i change the position of the footer to block so that it won't overlap. 当距底部等于或小于10像素时,我将页脚的位置更改为“阻止”,以使其不会重叠。

When closing the panel, I wait for the body height to go back to it's original height. 关闭面板时,我等待车身高度恢复到原始高度。 When that happens, I change the position back to absolute. 发生这种情况时,我会将位置改回绝对位置。 Obviously you will have to modify this to fit your page, but the concept should work. 显然,您必须对其进行修改以适合您的页面,但是该概念应该起作用。

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

相关问题 我可以使用scrollTo来解决slideToggle页脚问题吗? - Can I use scrollTo in order to fix slideToggle footer issue? 如何使用带有持续时间和缓动的slideToggle()? - How can I use slideToggle() with a duration and easing? 如何在多个元素上使用jQuery slideToggle? - How do I use jQuery slideToggle on multiple elements? 如何将jquery slidetoggle与许多内容框一起使用? - How can I use jquery slidetoggle with many content boxes? 我有一个菜单,当我从ul按下另一个li时,我不会如何正确使用slideToggle,slideDown和slideUp? - I have a menu and I don't how to use proprely slideToggle, to slideDown and slideUp when i pressed another li from ul? 如何将jQuery的slideToggle()应用于$(this)并执行与所有其他元素相反的操作? - How do I apply jQuery's slideToggle() to $(this) and do the opposite to all other elements? 如何在一组元素上使用slideToggle? - How to use slideToggle on a set of elements? 如何限制我可以使用 slideToggle 的次数? - How do I set a limit on how many times I can use slideToggle? 为什么当我将轨道推到数组时,数组中的所有元素都改变了 - why when I push the track to array, all the elements in array changed 当我单击一个切换时,所有的JQuery SlideToggle都将打开 - All of JQuery SlideToggle are opening when I clicked one toggle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM