FirefoxとIEで美しく機能するサイズ変更可能なdivのコードを見つけましたが、Chromeでは拡張が非常に困難です。拡張しようとすると無視されることがよくあります。これがなぜなのかさえわかりません-トラブルシューティングは難しいです。
chromeがこのdivの拡張を拒否することが多い理由についてのヒントがあれば便利です。自分で試してみてください。
#mydiv{
position:relative;
top:0px;
left:0px;
width:250px;
border: 1px solid #808080;
overflow: auto;
}
#statusbar{
cursor: s-resize;
position:relative;
display:block;
background-color: #c0c0c0;
font-size: 0px;
margin:0;
height:5px;
border: 1px solid #808080;
padding:0;
width: 250px;
}
スクリプト:
var curHeight=0;
var curMousePos=0;
var mouseStatus='up';
var curEvent;
//this function gets the original div height
function setPos(e){
curEvent=(typeof event=='undefined'?e:event);
mouseStatus='down';
//gets position of click
curMousePos=curEvent.clientY;
curHeight=parseInt(document.getElementById('mydiv').style.height.split('p')[0]);
}
//this changes the height of the div while the mouse button is depressed
function getPos(e){
if(mouseStatus=='down'){
curEvent=(typeof event=='undefined'?e:event);
//how many px to update the div? difference of previous and current positions
var pxMove=parseInt(curEvent.clientY-curMousePos);
var newHeight=parseInt(curHeight+pxMove);
//conditional to set minimum height to 5
newHeight=(newHeight<5?5:newHeight);
//set the new height of the div
document.getElementById('mydiv').style.height=newHeight+'px';
}
}
最後にHTML:
<div>
<div id="mydiv" style="height: 250px; min-height:150px; ">
<div></div>
</div>
<div onmousedown="setPos(event)" onmouseup="mouseStatus='up'" id="statusbar"></div>
</div>
編集:chromeはCSS3プロパティRESIZEをサポートしているようです。これは素晴らしく、私が使用したJSアプローチよりも完全に優れています。それでも、上記のコードがFF / IEの場合と同じようにクロムで機能することを望みます。そうすれば、ブラウザーの種類を確認する必要がなくなります。