javascript - Apply bootstrap on div width change instead of window change -
i have div expanding dynamically in project. need apply bootstrap columns style expanding div. applying based upon window resize not div size change.
here code was:
<!doctype html> <html lang="en"> <head> <title>bootstrap example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script> $(document).ready(function(){ $("button").click(function(){ $("div").width($("div").width()+20); }); }); </script> </head> </head> <body> </br> <div class="container-fluid" style="background-color:orange;width:200px;height:200px;"> <div class="col-sm-6" style="background-color:lavender;"> <p>lorem ipsum dolor sit amet</p> </div> <div class="col-sm-6" style="background-color:lavenderblush;"> <p>sed ut perspiciatis unde omnis </p> </div> </div> <button>expand</button> </body> </html> the button expands div continuesly on each click.
please on apply bootstrap style dynamically expanded div.
- you give div inline style width in px.
- parent div overflow:auto.
- change width in column width in jquery
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script> $(document).ready(function(){ console.log($("div").width()); $("button").click(function(){ $("div.col-sm-6").width($("div.col-sm-6").width()+20); }); }); </script> <div class="container-fluid" style="background-color:orange;height:200px;overflow:auto;"> <div class="col-sm-6 " style="background-color:lavender;"> <p>lorem ipsum dolor sit amet </p> </div> <div class="col-sm-6 " style="background-color:lavenderblush;"> <p>sed ut perspiciatis unde omnis</p> </div> </div> <button>expand</button>
Comments
Post a Comment