при нажатии на раздел меню поворачивается маркер
Вложений: 2
Здравствуйте товарищи! Помогите пожалуйста.
Имеется меню "Аккордеон" с двумя разделами, содержащими подразделы. При нажатии на раздел, он раскрывается и при этом маркер (стрелка), имеющаяся на кнопке раздела, должна повернуться на 90 градусов, при закрытии вернуться в исходное положение. На данный момент стрелка выполняет свою заданную роль только при наведении на неё курсора. Как сделать так чтобы она поворачивалась именно при нажатии на раздел. <html> <head> <script src="jquery-1.4.2.min.js" type="text/javascript"></script> <script src="menu.js" type="text/javascript"></script> <script type="text/javascript" src="jQueryRotate.js"></script> <link rel="stylesheet" type="text/css" href="style.css" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> <body> <div class="container"> <div align="center"> <ul class="menu collapsible"> <li class="expand"> <a href="#">Рубрики<img src="blockbullets.png" style="margin-left:120px" id="rotateImg"> </h3></a> <ul class="acitem"> <li><a href="#">Рубрика 1</a></li> <li><a href="#">Рубрика 2</a></li> <li><a href="#">Рубрика 3</a></li> </ul> </li> <!-- =====================Поворот=================================== --> <script type="text/javascript"> jQuery("#rotateImg").rotate({ bind: { mouseover : function() { jQuery(this).rotate({animateTo:90}) }, mouseout : function() { jQuery(this).rotate({animateTo:0}) } } }); </script> <!-- ===================================================== --> <li> <a href="#">Месяцы<img src="blockbullets.png" style="margin-left:126px" id="rotateImg"> </h3></a> <ul class="acitem"> <li><a href="#">Январь (10)</a></li> <li><a href="#">Февраль (15)</a></li> <li><a href="#">Март (8)</a></li> <li><a href="#">Апрель (12)</a></li> </ul> </li> </ul> </div> </div> </body> </html> Код menu.js jQuery.fn.initMenu = function() { return this.each(function(){ var theMenu = $(this).get(0); $('.acitem', this).hide(); $('li.expand > .acitem', this).show(); $('li.expand > .acitem', this).prev().addClass('active'); $('li a', this).click( function(e) { e.stopImmediatePropagation(); var theElement = $(this).next(); var parent = this.parentNode.parentNode; if($(parent).hasClass('noaccordion')) { if(theElement[0] === undefined) { window.location.href = this.href; } $(theElement).slideToggle('normal', function() { if ($(this).is(':visible')) { $(this).prev().addClass('active'); } else { $(this).prev().removeClass('active'); } }); return false; } else { if(theElement.hasClass('acitem') && theElement.is(':visible')) { if($(parent).hasClass('collapsible')) { $('.acitem:visible', parent).first().slideUp('normal', function() { $(this).prev().removeClass('active'); } ); return false; } return false; } if(theElement.hasClass('acitem') && !theElement.is(':visible')) { $('.acitem:visible', parent).first().slideUp('normal', function() { $(this).prev().removeClass('active'); }); theElement.slideDown('normal', function() { $(this).prev().addClass('active'); }); return false; } } } ); }); }; $(document).ready(function() {$('.menu').initMenu();}); Все исходники имеются во вложениях. |
Замени в menu.js свою функцию на эту:
jQuery.fn.initMenu = function() { return this.each(function(){ var theMenu = $(this).get(0); $('.acitem', this).hide(); $('li.expand > .acitem', this).show(); $('li.expand > .acitem', this).prev().children().first().rotate({animateTo:90}); $('li.expand > .acitem', this).prev().addClass('active'); $('li a', this).click( function(e) { e.stopImmediatePropagation(); var theElement = $(this).next(); var parent = this.parentNode.parentNode; if($(parent).hasClass('noaccordion')) { if(theElement[0] === undefined) { window.location.href = this.href; } $(theElement).slideToggle('normal', function() { if ($(this).is(':visible')) { $(this).prev().addClass('active'); } else { $(this).prev().removeClass('active'); } }); return false; } else { if(theElement.hasClass('acitem') && theElement.is(':visible')) { $('.acitem:visible', parent).prev().children().rotate({animateTo:0}); if($(parent).hasClass('collapsible')) { $('.acitem:visible', parent).first().slideUp('normal', function() { $(this).prev().removeClass('active'); } ) return false; } return false; } if(theElement.hasClass('acitem') && !theElement.is(':visible')) { $('.acitem:visible', parent).prev().children().rotate({animateTo:0}); $('.acitem:visible', parent).first().slideUp('normal', function() { $(this).prev().removeClass('active'); }); theElement.slideDown('normal', function() { $(this).prev().children().first().rotate({animateTo:90}); $(this).prev().addClass('active'); }); return false; } } } ); }); }; и удали за ненадобностью из index.html этот кусок кода: <!-- =====================Поворот=================================== --> <script type="text/javascript"> jQuery("#rotateImg").rotate({ bind: { mouseover : function() { jQuery(this).rotate({animateTo:90}) }, mouseout : function() { jQuery(this).rotate({animateTo:0}) } }); </script> <!-- ===================================================== --> |
JuliusCaesar, Большое спасибо, выручил!!!:thanks:
Подскажите также если нетрудно, - можно ли увеличить скорость поворота стрелки? Иначе она поворачивается с некоторым лагом. |
понял про лаг, это не из-за скорости, переделал:
jQuery.fn.initMenu = function() { return this.each(function(){ var theMenu = $(this).get(0); $('.acitem', this).hide(); $('li.expand > .acitem', this).show(); $('li.expand > .acitem', this).prev().children().first().rotate({animateTo:90}); $('li.expand > .acitem', this).prev().addClass('active'); $('li a', this).click( function(e) { e.stopImmediatePropagation(); var theElement = $(this).next(); var parent = this.parentNode.parentNode; if($(parent).hasClass('noaccordion')) { if(theElement[0] === undefined) { window.location.href = this.href; } $(theElement).slideToggle('normal', function() { if ($(this).is(':visible')) { $(this).prev().addClass('active'); } else { $(this).prev().removeClass('active'); } }); return false; } else { if(theElement.hasClass('acitem') && theElement.is(':visible')) { $(theElement).prev().children().first().rotate({animateTo:0}); if($(parent).hasClass('collapsible')) { $('.acitem:visible', parent).first().slideUp('normal', function() { $(this).prev().removeClass('active'); } ) return false; } return false; } if(theElement.hasClass('acitem') && !theElement.is(':visible')) { $(theElement).prev().children().first().rotate({animateTo:90}); $('.acitem:visible', parent).first().prev().children().first().rotate({animateTo:0}); $('.acitem:visible', parent).first().slideUp('normal', function() { $(this).prev().removeClass('active'); }); theElement.slideDown('normal', function() { $(this).prev().addClass('active'); }); return false; } } } ); }); }; но если надо ускорить анимацию поворота, то удобнее всего в файле jQueryRotate.js поменять выставленное значение по умолчанию на свое в этой строке: this._parameters.duration = parameters.duration || this._parameters.duration || 1000;Поставь например 200 вместо 1000)) А если хочешь, чтобы вкладки быстрее сворачивались и открывались, меняй в menu.js везде slideUp('normal'...на slideUp('fast'... |
Весьма признателен дружище!!! То что надо!!!!!!!:dance:
|
не за что)))
|
Часовой пояс GMT +3, время: 22:31. |