简体   繁体   English

如何在不影响页面布局的情况下使用jQuery扩展框的大小

[英]How to Expand a Box Size Using jQuery Without affecting Page Layout

I would like to run a jquery which extends a box(div) without affecting on page layout.Here is a sample http://themes.ddwebstudios.net/?theme=photon&type=html 我想运行一个扩展box(div)而不影响页面布局的jQuery。这里是一个示例http://themes.ddwebstudios.net/?theme=photon&type=html

As you can see if you mouse over on the small transparent box under the image (accross the page) the box will be slideup without changing the page size. 如您所见,如果将鼠标悬停在图像下方的透明小框上(整个页面),则该框将向上滑动而不更改页面大小。

I know how to use .hide() and .show() or slidedown and slideup functions with a display:hidden; 我知道如何在显示中使用.hide()和.show()或slidedown和slideup函数: box format but as you know there are some issue here as I would likw to display a portion of box and also I dont want to have any changes on pagelayout 框格式,但是如您所知,这里有些问题,因为我希望显示框的一部分,而且我也不想在pagelayout上进行任何更改

Here is the sample which I tried to figure out how to do it, Can you please take a look at that and let me know how I can add a portion of magicDiv box (5% of top) before the row_3 and extend it to full size using jquery functions without affecting(defarming) the page layout? 这是我试图找出方法的示例,请您看看,让我知道如何在row_3之前添加magicDiv框的一部分(顶部的5%)并将其扩展为完整的使用jquery函数的大小,而不会影响(布局)页面布局?

http://jsfiddle.net/Behseini/nuC69/2/ http://jsfiddle.net/Behseini/nuC69/2/

Thanks for your time in advance. 谢谢您的时间。

The boxes do not change the page size because they use absolute positioning and z-index. 这些框不会更改页面大小,因为它们使用绝对定位和z-index。

If you inspect the album-thumbs div by right clicking on it when it opens, you'll see that it's done with CSS: 如果您在打开album-thumbs div时右键单击它,您会发现它是使用CSS完成的:

在此处输入图片说明

The key elements being: 关键要素是:

position: absolute;
z-index: 10;

Additionally, and this wasn't part of your question, you would use display: none; 另外,这也不是问题的一部分,您应该使用display: none; to avoid affecting page layout or visibility: hidden; 为了避免影响页面布局或visibility: hidden; to still have the div affect page layout. 仍然使div影响页面布局。 ( display: hidden; , as you wrote it, is not valid CSS) display: hidden;如您所写,不是有效的CSS)

Kato is spot on. 加藤是现场。 Here is a little snippet for show hide() portion of jQuery() 这是jQuery()的show hide()部分的小片段

Mine is a little different as I like to use arrays to store the height of expanding windows. 我的有点不同,因为我喜欢使用数组来存储扩展窗口的高度。 This allows me to have expanding windows of various heights and less jQuery code 这使我可以扩展各种高度的窗口,并减少jQuery代码

$(document).ready(function () {
    //create a string array to store various window sizes then based upon the attribute id of the element


        //load the apporaiate array value
        var winHeight = ["220px",
                         "100px",
                         "90px",
                         "400px",
                         "150px"];

    $(function () {
        $('.div1').hide();
    });

    $('.div2').click(function () {
        var cssProp = winHeight[$(this).attr('id')];

        if ($('.div1').is(':hidden')) {
            $('.div1').show();
            $('.div1').animate({ "height": cssProp }, 'slow');
        }
        else {
            $('.div1').hide("slow");
            $('.div1').animate({ "height": "0px" }, 'slow');
        }
    });

The only css applied was 唯一应用的CSS是

.div1
{
    margin: 5px;
    height: 0px;
    font-size: .9em;
    margin-left: auto;
    margin-right: auto;
}

The value is assigned by picking up the attribute id in the div element 通过在div元素中拾取属性ID来分配值

<div id="1" class="div2" /> // would set the height to 100px

when using hide() it attaches the attribute hidden to the element which is how I am testing to see the "visual" state of the div element. 当使用hide()时,它将隐藏的属性附加到元素上,这就是我正在测试的div元素的“可视”状态。 In this example I have this on a click event but you could change your event logic to .hover() if needed 在此示例中,我在click事件上有此事件,但是如果需要,您可以将事件逻辑更改为.hover()

I have modified your original jsFiddle file to show a working example 我已经修改了您的原始jsFiddle文件以显示一个有效的示例

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

相关问题 如何在不影响其他元素的情况下扩展DIV - How to expand a DIV without affecting other elements 在不影响页面布局的情况下将页面缩小到 75% - zoom out page to 75% without affecting page layout 您可以在不影响 Box 大小的情况下显示图像吗? - Can you display an image without affecting the Box size? 使用jQuery增大/缩小图像库,而不会影响布局 - grow/shrink image gallery with jquery WITHOUT affecting the layout 如何在不影响样式的情况下阻止页面滚动? - How to block the page scrolling without affecting the style? 如何在不影响此参数的情况下将参数绑定到jQuery回调 - How to bind an argument to a jquery callback without affecting this 如何使用jquery ajax填充div而不影响同一html页面中的其他内容? - How to use jquery ajax to fill a div without affecting other contents in the same html page? 如何在PHP中使用ajax jquery将列表框值发送到另一个列表框而不刷新页面 - How can send one list box value to another list box without refreshing page using ajax jquery in php 在页面上包含两个版本的jQuery,而不会影响旧插件 - Include two versions of jQuery on a page without affecting old plugins <a>使用 javascript 扩展 a 的字体大小而不影响其他的填充</a><a></a> - Expanding a font size of a <a> using javascript without affecting the padding of the other <a>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM