Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 08.12.2014, 21:59
Интересующийся
Отправить личное сообщение для kirill1989 Посмотреть профиль Найти все сообщения от kirill1989
 
Регистрация: 17.06.2013
Сообщений: 13

onmouseover проблема
Доброго времени суток всем! Проблема такая, создал я графическую кнопку меню, порезал на три части, сделал так что бы она растягивалась в зависимости от размера ссылки. Нужен был эффект hover изменения (картинки при наведении), CSS средствами решить не удалось, поскольку при наведении на одну часть кнопки одна чать и менялась. Применил JavaScript, назначил каждой ячейки td свой id. Все работает но только для первого пункта меню. Это как я понял каждой ячейки нужно задавать уникальный id и прописывать код? Есть ли какое то унивирсальное решение?
Ответить с цитированием
  #2 (permalink)  
Старый 08.12.2014, 22:02
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,064

kirill1989,
class
Ответить с цитированием
  #3 (permalink)  
Старый 08.12.2014, 22:04
Интересующийся
Отправить личное сообщение для kirill1989 Посмотреть профиль Найти все сообщения от kirill1989
 
Регистрация: 17.06.2013
Сообщений: 13

А можно по подробнее пожалуйста, я в JavaScript новичок
Ответить с цитированием
  #4 (permalink)  
Старый 08.12.2014, 22:09
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,064

kirill1989,
делайте макет -- но скорее всего вам нужен специалист по css, а не js.
Ответить с цитированием
  #5 (permalink)  
Старый 08.12.2014, 22:09
Интересующийся
Отправить личное сообщение для kirill1989 Посмотреть профиль Найти все сообщения от kirill1989
 
Регистрация: 17.06.2013
Сообщений: 13

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Документ без названия</title>

<style type="text/css">
.button{
	background:url(center_fiolet.png);
	
	width: auto;
	height: 54px;
	background-repeat:repeat-x;
}



.left_green{
	background:url(left_green.png);
	background-repeat:no-repeat;
	width:19px;
	height:51px;
}


.button2{
	transition:0.5s;
	background:url(center_green.png);
	width: auto;
	height: 54px;
	background-repeat:repeat-x;
	
}






.rigth_green{
	background:url(right_green.png);
	background-repeat:no-repeat;
	width:19px;
	height:51px;
}

.text_href{font-family: Basic, sans-serif;
font-size: 18px;
font-style: normal;
font-variant: normal;
font-weight: normal;
font-stretch: normal;
line-height: 1.3em;
color: #453269;
text-decoration:none;}




/*.button2:hover{
	 transition: 0.5s;
	background:url(center_active.png);
	width:auto;
	height:54px;
	background-repeat:repeat-x;
}*/


/*.left_green:hover{
	 transition: 0.5s;
	 background:url(left_active.png);
	width:19px;
	height:50px;
	background-repeat:no-repeat;
}*/





.test{
	background:url(button_active3.png);
	background-repeat:repeat-x;
	width: auto;
	height:54px;
	
}

</style>


<script type="text/javascript">
 //дожидаемся полной загрузки страницы
window.onload = function () {
  //ищем элемент по селектору
  var a = document.querySelector('#hover');
  var a2 = document.querySelector('#hover2');
  var a3 = document.querySelector('#hover3');
  var href = document.querySelector('#text_href');
  //вешаем на него события
  
 
  
 /* a.onmouseout = function(e) {
    document.getElementById('hover').style.background='url(left_green.png)';
	document.getElementById('hover').style.backgroundRepeat='no-repeat';
	document.getElementById('hover').style.width='19px';
	document.getElementById('hover').style.height='51px';
	document.getElementById('hover').style.transition='0.5s';
  }*/

  a.onmouseover=function(e) {
     document.getElementById('hover').style.background='url(left_active.png)';
	document.getElementById('hover').style.backgroundRepeat='no-repeat';
	document.getElementById('hover').style.width='19px';
	document.getElementById('hover').style.height='51px';
	document.getElementById('hover').style.transition='0.3s';
	
	
	 document.getElementById('hover2').style.background='url(center_active.png)';
	document.getElementById('hover2').style.backgroundRepeat='repeat-x';
	document.getElementById('hover2').style.width='auto';
	document.getElementById('hover2').style.height='51px';
	document.getElementById('hover2').style.transition='0.3s';
	document.getElementById('text_href').style.color='#E1FBA9';
	document.getElementById('text_href').style.transition='0.3s';
	
	
	
	
	
	document.getElementById('hover3').style.background='url(right_active.png)';
	document.getElementById('hover3').style.backgroundRepeat='no-repeat';
	document.getElementById('hover3').style.width='19px';
	document.getElementById('hover3').style.height='51px';
	document.getElementById('hover3').style.transition='0.3s';
	
	
  };
  
  a2.onmouseover=function(e) {
     document.getElementById('hover').style.background='url(left_active.png)';
	document.getElementById('hover').style.backgroundRepeat='no-repeat';
	document.getElementById('hover').style.width='19px';
	document.getElementById('hover').style.height='51px';
	document.getElementById('hover').style.transition='0.3s';
	
	 document.getElementById('hover2').style.background='url(center_active.png)';
	document.getElementById('hover2').style.backgroundRepeat='repeat-x';
	document.getElementById('hover2').style.width='auto';
	document.getElementById('hover2').style.height='51px';
	document.getElementById('hover2').style.transition='0.3s';
	document.getElementById('text_href').style.color='#E1FBA9';
	document.getElementById('text_href').style.transition='0.3s';
	
	
	
	document.getElementById('hover3').style.background='url(right_active.png)';
	document.getElementById('hover3').style.backgroundRepeat='repeat-x';
	document.getElementById('hover3').style.width='19px';
	document.getElementById('hover3').style.height='51px';
	document.getElementById('hover3').style.transition='0.3s';
	
	
  };
  
  a3.onmouseover=function(e) {
     document.getElementById('hover').style.background='url(left_active.png)';
	document.getElementById('hover').style.backgroundRepeat='no-repeat';
	document.getElementById('hover').style.width='19px';
	document.getElementById('hover').style.height='51px';
	document.getElementById('hover').style.transition='0.3s';
	
	 document.getElementById('hover2').style.background='url(center_active.png)';
	document.getElementById('hover2').style.backgroundRepeat='repeat-x';
	document.getElementById('hover2').style.width='auto';
	document.getElementById('hover2').style.height='51px';
	document.getElementById('hover2').style.transition='0.3s';
	document.getElementById('text_href').style.color='#E1FBA9';
	document.getElementById('text_href').style.transition='0.3s';
	
	document.getElementById('hover3').style.background='url(right_active.png)';
	document.getElementById('hover3').style.backgroundRepeat='no-repeat';
	document.getElementById('hover3').style.width='19px';
	document.getElementById('hover3').style.height='51px';
	document.getElementById('hover3').style.transition='0.3s';
	
	
  };
  
  //Смена меню на исходную позицию
  
  a.onmouseout=function(e) {
     document.getElementById('hover').style.background='url(left_green.png)';
	document.getElementById('hover').style.backgroundRepeat='no-repeat';
	document.getElementById('hover').style.width='19px';
	document.getElementById('hover').style.height='51px';
	document.getElementById('hover').style.transition='0.3s';
	
	 document.getElementById('hover2').style.background='url(center_green.png)';
	document.getElementById('hover2').style.backgroundRepeat='repeat-x';
	document.getElementById('hover2').style.width='auto';
	document.getElementById('hover2').style.height='51px';
	document.getElementById('hover2').style.transition='0.3s';
	document.getElementById('text_href').style.color='#453269';
	document.getElementById('text_href').style.transition='0.3s';
	
	document.getElementById('hover3').style.background='url(right_green.png)';
	document.getElementById('hover3').style.backgroundRepeat='no-repeat';
	document.getElementById('hover3').style.width='19px';
	document.getElementById('hover3').style.height='51px';
	document.getElementById('hover3').style.transition='0.3s';
	
	
  };
  
  a2.onmouseout=function(e) {
     document.getElementById('hover').style.background='url(left_green.png)';
	document.getElementById('hover').style.backgroundRepeat='no-repeat';
	document.getElementById('hover').style.width='19px';
	document.getElementById('hover').style.height='51px';
	document.getElementById('hover').style.transition='0.3s';
	
	 document.getElementById('hover2').style.background='url(center_green.png)';
	document.getElementById('hover2').style.backgroundRepeat='repeat-x';
	document.getElementById('hover2').style.width='auto';
	document.getElementById('hover2').style.height='51px';
	document.getElementById('hover2').style.transition='0.3s';
	document.getElementById('text_href').style.color='#453269';
	document.getElementById('text_href').style.transition='0.3s';
	
	document.getElementById('hover3').style.background='url(right_green.png)';
	document.getElementById('hover3').style.backgroundRepeat='repeat-x';
	document.getElementById('hover3').style.width='19px';
	document.getElementById('hover3').style.height='51px';
	document.getElementById('hover3').style.transition='0.3s';
	
	
  };
  
  a3.onmouseout=function(e) {
     document.getElementById('hover').style.background='url(left_green.png)';
	document.getElementById('hover').style.backgroundRepeat='no-repeat';
	document.getElementById('hover').style.width='19px';
	document.getElementById('hover').style.height='51px';
	document.getElementById('hover').style.transition='0.3s';
	
	 document.getElementById('hover2').style.background='url(center_green.png)';
	document.getElementById('hover2').style.backgroundRepeat='repeat-x';
	document.getElementById('hover2').style.width='auto';
	document.getElementById('hover2').style.height='51px';
	document.getElementById('hover2').style.transition='0.3s';
	document.getElementById('text_href').style.color='#453269';
	document.getElementById('text_href').style.transition='0.3s';
	
	document.getElementById('hover3').style.background='url(right_green.png)';
	document.getElementById('hover3').style.backgroundRepeat='no-repeat';
	document.getElementById('hover3').style.width='19px';
	document.getElementById('hover3').style.height='51px';
	document.getElementById('hover3').style.transition='0.3s';
	
	
  };
  
  
  
}
</script>


</head>

<body>
 <table border="0" cellpadding="0" cellspacing="0">
   <tr>
     <td valign="top">
     <img src="left_fiolet.png" />
     </td>
     <td class="button"><div style="padding-bottom:0px;">
        <a href="#">ССылка №1</a></div>
     </td>
     <td valign="top">
     <img src="right_fiolet.png" />
     </td><sction id="some">
     <td class="left_green" id="hover">
       
     </td>
     
     <td class="button2" id="hover2">
       <div style="padding-bottom:10px;">
        <a href="#" id="text_href" class="text_href">Ссылка. Ссылка №2</a></div>
     </td>
     
     <td class="rigth_green" id="hover3">
     
     </td>
     
     <td class="test">
       <a href="#">Тестова кнопка меню</a>
     </td>
    </tr>
  </table>
   </body>
</html>


вот собственно код
Ответить с цитированием
  #6 (permalink)  
Старый 08.12.2014, 22:16
Аватар для Aetae
Тлен
Отправить личное сообщение для Aetae Посмотреть профиль Найти все сообщения от Aetae
 
Регистрация: 02.01.2010
Сообщений: 6,480

kirill1989, парень ты из комы вышел? Уже лет десять никто так не делает.

Если я правильно понял чего ты хочешь, то в современном вебе это выглядит примерно так:
<style>
  a{
    border-style: solid; 
    border-width: 6px 9px 3px;
    border-image: url(http://javascript.ru/forum/images/editor/css.png) 6 9 3 fill stretch;
    padding: 2px 5px;
    transition:padding 1s;
  }
  a:hover{
    padding: 2px 25px;
  }
</style>
<a href="http://javascript.ru">javascript.ru</a>
(и ещё пяток способов)
__________________
29375, 35
Ответить с цитированием
  #7 (permalink)  
Старый 08.12.2014, 22:27
Интересующийся
Отправить личное сообщение для kirill1989 Посмотреть профиль Найти все сообщения от kirill1989
 
Регистрация: 17.06.2013
Сообщений: 13

Сообщение от Aetae Посмотреть сообщение
kirill1989, парень ты из комы вышел? Уже лет десять никто так не делает.

Если я правильно понял чего ты хочешь, то в современном вебе это выглядит примерно так:
<style>
  a{
    border-style: solid; 
    border-width: 6px 9px 3px;
    border-image: url(http://javascript.ru/forum/images/editor/css.png) 6 9 3 fill stretch;
    padding: 2px 5px;
    transition:padding 1s;
  }
  a:hover{
    padding: 2px 25px;
  }
</style>
<a href="http://javascript.ru">javascript.ru</a>
(и ещё пяток способов)
Я имел ввиду вот есть у меня кнопка меню, я ее сделал резиновой в зависимости от длины ссылки ( при загрузки страницы она принимает автоматически свой размер ), но при наведении на кнопку нужно что бы три части меняло цвет. Если возможен вариант сделать кнопку резиновой изначально без разрезки на три части, то подскажите пожалуйста.
Ответить с цитированием
  #8 (permalink)  
Старый 08.12.2014, 22:44
Аватар для Aetae
Тлен
Отправить личное сообщение для Aetae Посмотреть профиль Найти все сообщения от Aetae
 
Регистрация: 02.01.2010
Сообщений: 6,480

Сообщение от kirill1989 Посмотреть сообщение
Если возможен вариант сделать кнопку резиновой изначально без разрезки на три части, то подскажите пожалуйста.
В моём коде именно такая.
__________________
29375, 35
Ответить с цитированием
  #9 (permalink)  
Старый 08.12.2014, 23:40
Интересующийся
Отправить личное сообщение для kirill1989 Посмотреть профиль Найти все сообщения от kirill1989
 
Регистрация: 17.06.2013
Сообщений: 13

Сообщение от Aetae Посмотреть сообщение
В моём коде именно такая.
Спасибо огромное тема закрыта!
Ответить с цитированием
Ответ



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

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


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
проблема с событиями onMouseOut и onMouseOver zaman Общие вопросы Javascript 1 15.11.2012 15:22
Изменением цвета рядка таблицы по onMouseOver - проблема Flashbacks Элементы интерфейса 2 08.04.2012 14:52
проблема с onmouseover Ponomareva_AS jQuery 4 09.08.2011 12:44
проблема с событиями onMouseOut и onMouseOver IIIgun Общие вопросы Javascript 16 13.05.2011 21:55
FireFox: onmouseover не работает при зажатой кнопке мыши no. Общие вопросы Javascript 4 19.08.2008 13:43