解决方案 »
- 读取下拉框中的值 添加到同一页面的 tab表格中?
- javascript控制文本(div)的高度
- 国庆大散分,另外问个小问题。
- 求文字滚动JS代码
- div 层出现后,怎么样才能不让操作他后面的内容?
- 高手来看.关于prototype在自定义方法当中的属性无法引用的问题
- 请问验证码的ajax图片loading问题
- 请问在我家机子上下代码当按“浏览”onChange事件能触发而在公司的机子上却不能触发,为什么?
- 请问怎么通过javascript读当前的操作系统是98、winme还是2000、xp?
- document.oncontextmenun 着是什么意思
- js控制打印
- NTKO 控件如何自动载入一个空白文稿
var speed=3;
function contact(){
var oDiv=document.getElementById('content');
oDiv.style.width=oDiv.offsetWidth+speed+"px";
oDiv.style.height=oDiv.offsetHeight+speed+"px";
var t= window.setTimeout(contact,5);
if(oDiv.offsetWidth>=100){
window.clearTimeout(t);
}
}
</script>
<body>
</body>
</html>
.container{width:300px; height:300px; background:#9C0; position:relative; margin:150px auto 0}
#content{width:50px; height:50px; background:#F00; position:absolute; top:0; left:0}
</style>
<div class="container">
<div id="content" onmouseover="contact()"></div>
</div>
<script type="text/javascript">
var speed=3;
function contact(){
var oDiv=document.getElementById('content');
oDiv.style.width=oDiv.offsetWidth+speed+"px";
oDiv.style.height=oDiv.offsetHeight+speed+"px";
if(oDiv.offsetWidth<100){
window.setTimeout(contact,5);
}
}
</script>
var speed=3;
function contact(){
var oDiv=document.getElementById('content');
oDiv.style.width=oDiv.offsetWidth+speed+"px";
oDiv.style.height=oDiv.offsetHeight+speed+"px";
if(oDiv.offsetWidth<=100){
window.setTimeout(contact,5);
}
}
function contact2(){
var oDiv=document.getElementById('content');
oDiv.style.width=oDiv.offsetWidth-speed+"px";
oDiv.style.height=oDiv.offsetHeight-speed+"px";
if(oDiv.offsetWidth>=50){
window.setTimeout(contact,5);
}
}如果想让其,鼠标移出后再缩小,是否是这样写?这么些又错在哪里呢
<div class="container">
<div id="content" onmouseover="contact()" onmouseout="contact2()"></div>
</div>
.container{width:300px; height:300px; background:#9C0; position:relative; margin:150px auto 0}
#content{width:50px; height:50px; background:#F00; position:absolute; top:0; left:0}
</style>
<div class="container">
<div id="content" onmouseover="contact(1)" onmouseout="contact(0)"></div>
</div>
<script type="text/javascript">
var speed=3;
var maxWidth = 300;
var minWidth = 50;
var isLock = false;
function contact(isMouseOver){
if(isMouseOver){
var oDiv=document.getElementById('content');
if(oDiv.offsetWidth >= maxWidth){
return false;
}
oDiv.style.width=oDiv.offsetWidth+speed+"px";
oDiv.style.height=oDiv.offsetHeight+speed+"px";
if(oDiv.offsetWidth<maxWidth){
window.setTimeout("contact(1)",5);
}
}else{
var oDiv=document.getElementById('content');
if(oDiv.offsetWidth <= minWidth){
return false;
}
oDiv.style.width=oDiv.offsetWidth-speed+"px";
oDiv.style.height=oDiv.offsetHeight-speed+"px";
if(oDiv.offsetWidth>minWidth){
window.setTimeout("contact(0)",5);
}
}
}
还有点缺陷,大致就这个思路了
.container{width:300px; height:300px; background:#9C0; position:relative; margin:150px auto 0}
#content{width:50px; height:50px; background:#F00; position:absolute; top:0; left:0}
</style>
<div class="container">
<div id="content" onmouseover="contact(1)" onmouseout="contact(0)"></div>
</div>
<script type="text/javascript">
var speed=3;
var maxWidth = 300;
var minWidth = 50;
var sto1, sto2;
function contact(isMouseOver){
if(isMouseOver){
var oDiv=document.getElementById('content');
if(oDiv.offsetWidth >= maxWidth){
return false;
}
clearTimeout(sto2);
oDiv.style.width=oDiv.offsetWidth+speed+"px";
oDiv.style.height=oDiv.offsetHeight+speed+"px";
if(oDiv.offsetWidth<maxWidth){
sto1 = window.setTimeout("contact(1)",5);
}
}else{
var oDiv=document.getElementById('content');
if(oDiv.offsetWidth <= minWidth){
return false;
}
clearTimeout(sto1);
oDiv.style.width=oDiv.offsetWidth-speed+"px";
oDiv.style.height=oDiv.offsetHeight-speed+"px";
if(oDiv.offsetWidth>minWidth){
sto2 = window.setTimeout("contact(0)",5);
}
}
}
</script>