简体   繁体   English

如何使用javascript和html增大和减小div的大小

[英]how to increase and decrease the size of div using javascript and html

I want to resize the position of the div using javascript function. 我想使用javascript函数调整div的位置。 I was tried to solve that but this is not properly work. 我试图解决这个问题,但这不能正常工作。 In thet div only dragged right side. 在the div中只拖动了右侧。 i want to whener user drag cursor on div2 then change the style of the cursor and whenever user press the mouse left key and drag the left side then size of the div1 should be decresed and drag on right then side should be increse. 我想当用户在div2上拖动光标然后更改光标的样式时,每当用户按鼠标左键并拖动左侧时,div1的大小应减小,在右侧拖动则应增加。 My code is here. 我的代码在这里。

    <div onmousedown="dStarted(event);" onmousemove="dMoving(event,this);" onmouseup="dEnd(event,this);" style="float: left; height: 100%; border-right: solid 1px black; background-color:LightGrey" id="div1">
        <a href="#" onclick="toggle();">
            <img style="background-color:White;" id="imgToggle" />
        </a>
    </div>
    <div style="float: left; height: 100%;" runat="server" id="div3">
        <iframe frameborder="0" framespacing="0" id="frame2" runat="server" height="100%" width="100%" noresize="noresize" class="WZSplitterPanel"></iframe>
    </div>

        var dragged=false;
        function dStarted(event)
        {
            dragged =true;
        }


        function dMoving(event,ele)
        {
                ele.style.cursor = "e-resize";
                var div2 =document.getElementById("div2");
                div2.style.width = event.x;
                var frm1=document.getElementById("frame1");
                frm1.style.width=div2.style.width;
        }

        function dEnd(event, ele)
        {
            if(dragged)
            {
                ele.style.cursor = "default";
                dragged=false;
            }
            return;
        }

in that size only increse and cursor style not properly work. 在该大小下,仅增量和光标样式无法正常工作。 whener i move the cursor on div2 then cursor blink . 每当我将光标移动到div2上,然后光标闪烁。

I have taken 3 div , In div2(id="div2") take one iframe id="frame1" and in div1 id="div1" take one image and div3 id"div3" take one frame id="frame2". 我拍摄了3个div,在div2(id =“ div2”)中拍摄了一张iframe id =“ frame1”,在div1 id =“ div1”中拍摄了一张图片,而div3 id“ div3”拍摄了一帧id =“ frame2”。 i want to when drag the cursor right side then div2 and frame1 size should be decrese. 我想在将光标拖到右侧时将div2和frame1的大小减小。

Try changing the id's in your javascript to match the ones in the HTML that's where I would start. 尝试在您的JavaScript中更改ID以与HTML的ID匹配,这就是我要开始的地方。 Also make sure you're not getting errors in your browser's error console. 另外,请确保您没有在浏览器的错误控制台中收到错误消息。

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

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