简体   繁体   English

在点击时显示Divs内容

[英]Reveal Divs Content On Click

I'm not really sure how to word what I'm looking for in search engine terms, so what I'm trying to do is: 我不太确定如何用搜索引擎的术语表达我要寻找的内容,所以我想做的是:

I want to have a division, or two if that's what it takes, in the center of the page that when clicked seperates. 我想在单击的页面中间分开一个或两个(如果需要的话)。 Top portion slides up, bottom portion slides down and it reveals the website content in the middle. 顶部向上滑动,底部向下滑动,并在中间显示网站内容。


点击


滑动


I'm not exactly sure how word my search for something that does that properly. 我不太确定我该如何搜索能正确执行此操作的单词。 I've seen a few websites that have variations of this. 我见过一些对此有所变化的网站。 Only ones that open left/right though. 只有那些打开左/右。 I'm sure this is difficult, but any help towards achieving this would be greatly appreciated. 我确信这很困难,但是对实现这一目标的任何帮助将不胜感激。

Thanks in advance, Bc. 预先感谢,卑诗省。

If you're using JQuery, you can simply use slideUp and slideDown on the target div. 如果您使用的是JQuery,则只需在目标div上使用slideUpslideDown

Edit 编辑

Actually, in this case I think slideToggle is what you're looking for: 实际上,在这种情况下,我认为您正在寻找slideToggle

<script type='text/javascript'>
    $(document).ready(function() {
        $(".button").click(function() {
            $("#content).slideToggle();
        });
    });
</script>

<div class='button'>Top Panel</div>
<div id='content'>Content</div>
<div>Bottom Panel</div>

I think this is what you need : http://jsfiddle.net/WQCav/ 我认为这就是您需要的: http : //jsfiddle.net/WQCav/

HTML : HTML:

<div id="hider1" style="position:absolute;background-color:black;width:100%;height:50%;" onclick="displayWebsite();" ></div>
<div id="hider2" style="background-color:black;width:100%;height:50%;position:absolute;top:50%;" onclick="displayWebsite();" ></div>
HI

JS : JS:

var up,down;
function displayWebsite()
{
    if(typeof up!=="undefined")return;
    up=setInterval(goUp,20);
    down=setInterval(goDown,20);
}
function goUp(x)
{
    var h1=document.getElementById("hider1");
    if(h1.offsetHeight<=80)
    {
        clearInterval(up);
        return;
    }
    h1.style.height=parseInt(h1.style.height)-1+"%";
}
function goDown(x)
{
    var h2=document.getElementById("hider2");
    if(h2.offsetHeight<=80)
    {
        clearInterval(down);
        return;
    }
    h2.style.top=parseInt(h2.style.top)+1+"%";
    h2.style.height=parseInt(h2.style.height)-1+"%";
}

CSS : CSS:

html,body
{
    width:100%;
    height:100%;
}

I just finished fixing this issue. 我刚刚解决了这个问题。 I did not want the div to go over the material below it but shift it down. 我不希望div遍历其下的内容,而是将其下移。 This will get the division splitting in half feel that you want - you will need something below the sliding div(like another div, or a div that has some invisible height to it and height on Auto in CSS to make it work for your main wrap. 这将使分割分裂成您想要的一半感觉-您将需要在滑动div之下的某些东西(例如另一个div,或者具有不可见高度的div和CSS中Auto的高度,以使其适合您的主要包装。

Here is what I did: 这是我所做的:

My CSS: 我的CSS:

.slide {
    height:200px;
    background-color: white;
    padding:20px;
    margin-top:10px;
    -moz-box-shadow: inset 0 3px 8px rgba(0,0,0,.4);
    -webkit-box-shadow: inset 0 3px 8px rgba(0,0,0,.4);
    box-shadow: inset 0 3px 8px rgba(0,0,0,.24);

}




#show_div {
    margin-left: 40px;
    text-decoration: none;
    background-color: white;
    color: black;
    padding: 5px 10px;
    border: 1px solid #333;
    font-size: 20px;


}

This was to make it look pretty. 这是为了使其外观漂亮。 Below is more of the function: 以下是更多功能:

.show_hide {
    display:none;

Coding: In the header I put the JQ function: 编码:在标头中,我放入了JQ函数:

 $(document).ready(function(){

        $(".slide").hide();
        $(".show").show();

    $('.show').click(function(){
    $(".slide").slideToggle();
    });

});

Then in the div itself don't forget to place the actual good stuff that will style your div to perform the way you like: 然后在div本身中,不要忘了放置一些实际的好东西,这些东西会为div设置样式以执行您喜欢的方式:

<a id="show_div" href="#" class="show">Browse Styles</a>


    <div class="slide">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus fermentum, nibh at iaculis ultrices, mi eros tincidunt enim, vitae vehicula lectus odio a ipsum. Aliquam erat volutpat. Fusce id nisl sit amet diam iaculis pulvinar. Sed ultrices ullamcorper ornare. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis mi arcu, porta ut elementum et, ullamcorper sed eros. In euismod tellus sed ipsum adipiscing suscipit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac magna dui. Aenean nec leo libero. Pellentesque lacinia dolor a dui lacinia consectetur. Mauris euismod porta magna, non dignissim orci adipiscing malesuada. Phasellus nunc sapien, consectetur nec vestibulum ac, euismod a ipsum.

    </div>
​

The main back draw on this is that you will need to place one instance of the Jscript for each div that you want to use this for, otherwise they will all activate at the same time. 主要的缺点是您需要为每个要使用的div放置一个Jscript实例,否则它们将同时激活。 You can place the button(or link) anywhere on the page. 您可以将按钮(或链接)放置在页面上的任何位置。 I have a couple of them side by side and when clicked they split the page from the same location. 我有两个并排放置,单击它们会将页面从同一位置分开。

If you need multiple of these don't forget to give the divs unique ids and to change their name in the Jscript to make the magic happen. 如果您需要多个,请不要忘记给div赋予唯一的ID,并在Jscript中更改其名称以使魔术发生。

HERE IS A JFIDDLE EXAMPLE: http://jsfiddle.net/vH3cK/1/ 这是一个JFIDDLE示例: http : //jsfiddle.net/vH3cK/1/

Hope that helps! 希望有帮助!

The first "div" should be composed of two different divs, one for the top part and another for the bottom. 第一个“ div”应该由两个不同的div组成,一个用于顶部,另一个用于底部。 Your page content should be styled "display:none" at first. 首先,页面内容的样式应为“ display:none”。 When the user clicks on the first div, show the page content using "$(selector).slideDown(500)". 当用户单击第一个div时,使用“ $(selector).slideDown(500)”显示页面内容。 Would have to test it, but I think it should work like a charm. 必须进行测试,但我认为它应该像魅力一样工作。 You could try using .show(), .toggle() and different ammounts of time (in miliseconds) to see what fits best. 您可以尝试使用.show()、. toggle()和不同的时间量(以毫秒为单位),以查看最合适的时间。

jQuery .animate()函数也可能值得研究-它使用CSS,这通常是更好的做法。

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

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