Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 14.06.2015, 12:16
Интересующийся
Отправить личное сообщение для Дмитрий_Кирсанов Посмотреть профиль Найти все сообщения от Дмитрий_Кирсанов
 
Регистрация: 29.12.2010
Сообщений: 16

Подвинуть элемент влево при событии onmouseover
Почему не работает функция?

function Init()
{
  
  document.getElementById("left").onmouseover = function()
  {
    var computedStyle = getComputedStyle(document.getElementById("crazycircle"));
    if ((parseInt(computedStyle.marginTop) > -10) && (parseInt(computedStyle.marginTop) < 620) && (parseInt(computedStyle.marginLeft) > -10) 
	    && (parseInt(computedStyle.marginLeft) < 960))
    
	{   
      computedStyle.marginLeft = parseInt(computedStyle.marginLeft)+5+"px";
    }  
  }

  
}
 
window.onload = Init;




.crazycircle
{
  position: absolute;
  margin-top: 300px;    
  margin-left: 450px;
  width: 60px;
  height: 60px;
  background: url(circleimg/sadsmileface.jpeg);
}

.left
{
  position: relative;
  top: 0px;
  left: 0px;
  width: 5px;
  height: 55px;  
  background-color: green;
}

.right
{
  position: relative;
  top: -55px;
  left: 55px;
  width: 5px;
  height: 55px;  
  background-color: green;
}

.top
{
  position: relative;
  top: -115px;
  left: 0px;
  width: 60px;
  height: 5px;  
  background-color: green;
}

.low
{
  position: relative;
  top: -60px;
  left: 0px;
  width: 60px;
  height: 5px;  
  background-color: green;
}



<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>CrazyCircle</title>
    <link href="circlecss/crazycircle2.css" rel="stylesheet">
  </head>
  <body>
    <div>
	  <div class = "crazycircle" id = "crazycircle">
	    <div class = "left" id = "left"></div>
		<div class = "right" id = "right"></div>
		<div class = "top" id = "top"></div>
		<div class = "low" id = "low"></div>
	  </div>
	</div>  
    <script src = "/js/CrazyCircle.js"></script>
  </body>
</html>
Ответить с цитированием
  #2 (permalink)  
Старый 14.06.2015, 12:43
Аватар для KosBeg
Профессор
Отправить личное сообщение для KosBeg Посмотреть профиль Найти все сообщения от KosBeg
 
Регистрация: 22.05.2015
Сообщений: 384

первая проблемма
неправильно
window.onload = Init;

правильно
window.onload = Init*!*()*/!*;
Ответить с цитированием
  #3 (permalink)  
Старый 14.06.2015, 12:51
Аватар для KosBeg
Профессор
Отправить личное сообщение для KosBeg Посмотреть профиль Найти все сообщения от KosBeg
 
Регистрация: 22.05.2015
Сообщений: 384

когда навожу мышку - в консоли ошибка
*!*
NoModificationAllowedError: Modifications are not allowed for this document
*/!*
Ответить с цитированием
  #4 (permalink)  
Старый 14.06.2015, 18:04
Интересующийся
Отправить личное сообщение для Дмитрий_Кирсанов Посмотреть профиль Найти все сообщения от Дмитрий_Кирсанов
 
Регистрация: 29.12.2010
Сообщений: 16

я тоже вижу эту ошибку в 19 строке .js. А что она означает и как её исправить?
Ответить с цитированием
  #5 (permalink)  
Старый 14.06.2015, 18:25
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

Дмитрий_Кирсанов,
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>CrazyCircle</title>
<style>
.crazycircle
{
  position: absolute;
  margin-top: 300px;
  margin-left: 450px;
  width: 60px;
  height: 60px;
  background: url(circleimg/sadsmileface.jpeg) rgb(255, 0, 0);
}

.left
{
  position: relative;
  top: 0px;
  left: 0px;
  width: 5px;
  height: 55px;
  background-color: green;
}

.right
{
  position: relative;
  top: -55px;
  left: 55px;
  width: 5px;
  height: 55px;
  background-color: green;
}

.top
{
  position: relative;
  top: -115px;
  left: 0px;
  width: 60px;
  height: 5px;
  background-color: green;
}

.low
{
  position: relative;
  top: -60px;
  left: 0px;
  width: 60px;
  height: 5px;
  background-color: green;
}


</style>
  </head>
  <body>
    <div class="x">
	  <div class = "crazycircle" id = "crazycircle">
	    <div class = "left" id = "left"></div>
		<div class = "right" id = "right"></div>
		<div class = "top" id = "top"></div>
		<div class = "low" id = "low"></div>
	  </div>
	</div>
    <script>function Init()
{

  document.getElementById("left").onmouseover = function()
  {
    var computedStyle = getComputedStyle(document.getElementById("crazycircle"));
    if ((parseInt(computedStyle.marginTop) > -10) && (parseInt(computedStyle.marginTop) < 620) && (parseInt(computedStyle.marginLeft) > -10)
	    && (parseInt(computedStyle.marginLeft) < 960))

	{
      document.getElementById("crazycircle").style.marginLeft = parseInt(computedStyle.marginLeft)+5+"px";
    }
  }


}

window.onload = Init();
</script>
  </body>
</html>
Ответить с цитированием
  #6 (permalink)  
Старый 14.06.2015, 22:13
Интересующийся
Отправить личное сообщение для Дмитрий_Кирсанов Посмотреть профиль Найти все сообщения от Дмитрий_Кирсанов
 
Регистрация: 29.12.2010
Сообщений: 16

document.getElementById("crazycircle").style.margi nLeft - всё гениальное просто. Не правда ли?
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
открытие аттрибута REL при onmouseover masodov Элементы интерфейса 5 03.02.2010 14:39
Смена картинки (бекграунд дива ) при событии (нажатие клавиш или клавиши и мыши) Monster Events/DOM/Window 5 01.11.2009 01:16
Изменить стиль формы - бэкграунд при onmouseover petyaeva Элементы интерфейса 0 31.07.2009 11:31
Закрыть элемент при клике вне его masterm Общие вопросы Javascript 3 31.07.2009 11:27
FireFox: onmouseover не работает при зажатой кнопке мыши no. Общие вопросы Javascript 4 19.08.2008 13:43