码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript限制div不跑出屏幕外边

时间:2017-04-07 16:40:28      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:var   top   setw   clientx   window   eth   java   style   his   

 1 function fnMove(ev) {
 2     var event = ev || window.event;
 3     var l = event.clientX - this.disX;
 4     var t = event.clientY - this.disY
 5 
 6 
 7     if (l < 0) {
 8         l = 0;
 9     }
10     else if (l > document.documentElement.clientWidth - this.oDiv.offsetWidth) {
11 
12         l = document.documentElement.clientWidth - this.oDiv.offsetWidth
13     }
14     ;
15 
16     if (t < 0) {
17         t = 0;
18     }
19     else if (t > document.documentElement.clientHeight - this.oDiv.offsetHeight) {
20 
21         t = document.documentElement.clientHeight - this.oDiv.offsetHeight
22     }
23 
24     this.oDiv.style.left = l + ‘px‘; 
25    this.oDiv.style.top = t + ‘px‘;

 

JavaScript限制div不跑出屏幕外边

标签:var   top   setw   clientx   window   eth   java   style   his   

原文地址:http://www.cnblogs.com/gogeek/p/6678707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!