Blogger Information
Blog 7
fans 0
comment 0
visits 4810
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js操作点击按钮移动方块2019年1月20日16时22分
文俊的博客
Original
801 people have browsed it

实例

此操作请先定位元素在页面中的位置。

<style>
#bnt{
    margin-top:150px;
}
#move{
    height:30px;width:30px;background-color:lightpink;
    border-radius:50%;position: absolute;
}
</style>
<button id="bnt">点击</button>
<div id='move'>

</div>

<script>
var bnt = document.getElementById('bnt');
var box = document.getElementById('move');

bnt.onclick = function(){
    var timer=null;
    
    timer = setInterval(function(){
    
    clearInterval(timer);
    
    if(box.offsetLeft < 500){

    box.style.left = box.offsetLeft + 10 + 'px';

}else{
        clearInterval(timer);
    }
},100);
}

</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post