Программирование > JavaScript & JScript

Огрничение по перемещению объекта

(1/1)

sanika:
Есть блок, который можно перемещать по странице, этот блок обозначается как перемещаемы с помощью class="dragableElement"

и ЯваСкрипт, который собственно перемещает этот этот блок
(в приложении)

как сделать ограничение  для перемещения этого предмета по координатам?
т.е. если его Х>0, то Х=0 и вернуть в координату 0?
и если X

commander:




   test
   
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
 
  var elem=document.getElementById("block");
          if (tempY>400)
          {
          elem.style.top=400;
          }
          else
          {
          elem.style.top=tempY;
          }
          if (tempX>400)
          {
          elem.style.left=400;
          }
          else
          {
          elem.style.left=tempX;
          }
         
  return true
}

   
   
   .text_block{
   background:#000000;
   color:#ffffff;
   width:100px;
   text-align:center;
   position:absolute;
   top:20px;
   left:100px;
   }
   





test











оно?

sanika:
Да, спасибо большое

Навигация

[0] Главная страница сообщений

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
Перейти к полной версии