简体   繁体   English

Div根据图片调整大小请点击

[英]Div Resize according To image Click

I had two div in First Div had one image if i click of image left Div have to Re-size Right side Div have to show full page content and then if i click image again right side div have go to original position ..how to achieve this?? 我在第一个Div中有两个div,如果我单击图像左Div,则必须有一个图像。Div必须重新调整大小。右侧Div必须显示完整的页面内容,然后,如果我再次单击图像,则右边div必须转到原始位置。实现这一目标?

 <div style="border: 2px solid red;float:left;width:10%;height:400px "> <a href>Image Click</a></div>
<div style="border: 2px solid Blue;float:left;width:50%;height:500px "> Content to show in full page</div>

As you have not given any id/class to the image div you can try this: 由于您没有给图像div指定任何ID /类,因此您可以尝试以下操作:

$('div').find('a').on('click', function (e) {
   e.preventDefault();
   var height = $(this).closest('div').css('height');
   if (height === "400px") {
      $(this).closest('div').css('height', 'auto');
   } else {
      $(this).closest('div').css('height', '400px');
   }
});

Updated Demo 更新的演示

You can have two classes then add or remove the class from the <div class="smaller"> tag depending on the click. 您可以具有两个类,然后根据单击从<div class="smaller">标记中添加或删除该类。 the classes can be something like this: 这些类可以是这样的:

.bigger
{
border: 2px solid Blue;
float:left;
width:50%;
height:500px
}
.smaller{
border: 2px solid red;
float:left;
width:10%;
height:400px; 
}

Try This Code 试试这个代码

HTML 的HTML

 <div id="fdiv" style="border: 2px solid red;float:left;width:7%;height:400px "> <a href>Image Click</a></div>
<div id="sdiv" style="border: 2px solid Blue;float:left;width:50%;height:500px "> Content to show in full page</div>

JS JS

    <script type="text/javascript">
        $(document).ready(function () {
            var swidth=$('#sdiv').width();
$('#fdiv a').click(function (e) {
            e.preventDefault();

     var dupwidth=swidth;
            $('#sdiv').animate({ 'height': ($('#sdiv').height() == 500) ? 700 : 500 ,'width': ($('#sdiv').width() == swidth) ? parseInt(dupwidth)*1.75 : swidth }, 200);

        });

        });

    </script>

DEMO HERE 此处演示

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

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