简体   繁体   English

jQuery UI可调整大小的两个对象

[英]jQuery UI Resizable Two Objects

please me help with this one. 请我帮这个。

here the fiddle: http://jsfiddle.net/zerolfc/5fke9sb8/4/ 这里的小提琴: http : //jsfiddle.net/zerolfc/5fke9sb8/4/

when you are resizing down the object (.button) towards the footer and the object colliding with the footer. 当您将对象(.button)的尺寸缩小到页脚,并且该对象与页脚碰撞时。 How do I resize or change the height of the Article and change the Footer top position depends on how many pixel the object is resized. 如何调整或改变的高度Article ,改变Footer顶部位置取决于对象是由几个像素大小。

HTML 的HTML

<div>
    <div class="button">Resize Me</div>
    <article></article>
    <footer></footer>
</div>

CSS 的CSS

.button {
        background-color:#333;
        border-color:#333;
        color:#fff;
        position:absolute;
        top:200px;
        left:50px;
        height:50px;
        width:150px;
        text-align:center;
        line-height:inherit;
        z-index:1;
    }
    article {
        position:absolute;
        top:0;
        left:0;
        width:100%;
        height:300px;
        background-color:#ccc;
    }
    footer {
        position:absolute;
        top:300px;
        left:0;
        width:100%;
        height:100px;
        background-color:red;
    }

JS JS

$(function () {

    $('.button').resizable({
        create: function (e, ui) {
            var footer_current_top, body_current_height, object_current_height;
        },
        start: function (e, ui) {
            footer_current_top = parseInt($('footer').css('top'));
            body_current_height = parseInt($('article').css('height'));
            object_current_height = parseInt(ui.size.height);
        },
        stop: function (e, ui) {
            footer_current_top = parseInt($('footer').css('top'));
            body_current_height = parseInt($('article').css('height'));
            object_current_height = parseInt(ui.size.height);
        },
        resize: function (e, ui) {
            var handle = $(this).data('ui-resizable').axis;
            if (handle === 's') {

                if (parseInt(ui.position.top + ui.size.height) > footer_current_top) {

                    console.log('body H: ' + body_current_height + '; obj H: ' + object_current_height + '; obj new H: ' + ui.size.height);

                }

            }
        }
    });

});

You can adjust the css of both elements on resize: 您可以在调整大小时调整两个元素的css:

  • Adjust footer top css property 调整页脚top CSS属性
  • Adjust article height css property 调整文章height CSS属性

     function resizeCheck(element){ footer_current_top = parseInt($('footer').css('top')); body_current_height = parseInt($('article').css('height')); object_current_height = parseInt(element.size.height); var elementBottom=element.position.top + element.size.height; if (parseInt(elementBottom) > footer_current_top) { $("footer").css("top",elementBottom+"px"); $("article").css("height",elementBottom+"px"); } } $('.button').resizable({ resize: function (e, ui) { resizeCheck(ui); } }); 

FIDDLE 小提琴

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

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