Кнопка JavaScript
Помогите пожалуйста! Нужно чтоб при нажатии на "Фиксировать блок" включался скрипт, а при "Убрать фиксацию" выключался. Как это можно сделать?
Вот код кнопки <div class='open'>Фиксировать блок</div><div class='close'><a href='#top'>Убрать фиксацию</a></div> Файл у меня называется admin_fix.js Вот сам код скрипта jQuery(document).ready(function(){ /* функция кроссбраузерного определения отступа от верха документа к текущей позиции скроллера прокрутки */ function getScrollTop() { var scrOfY = 0; if( typeof( window.pageYOffset ) == "number" ) { //Netscape compliant scrOfY = window.pageYOffset; } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { //DOM compliant scrOfY = document.body.scrollTop; } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { //IE6 Strict scrOfY = document.documentElement.scrollTop; } return scrOfY; } jQuery(window).scroll(function() { fixPaneRefresh(); }); function fixPaneRefresh(){ if (jQuery("#toolbar").length) { var top = getScrollTop(); if (top < 410) jQuery("#toolbar").css("margin-top",410-top+"px"); else jQuery("#toolbar").css("margin-top","0"); } } }); |
это только один из множества способов
$('.open').live('click', function(){ $(this).addClass('fixed'); }); $('.close').live('click', function(){ $(document).find('.fixed').removeClass('fixed'); }); function fixPaneRefresh(){ if (jQuery("#toolbar").length && ! $(document).find('.fixed').length) { var top = getScrollTop(); if (top < 410) jQuery("#toolbar").css("margin-top",410-top+"px"); else jQuery("#toolbar").css("margin-top","0"); } } |
Спасибо большоеееееееее Ваш сайт суПЕР)
|
Часовой пояс GMT +3, время: 02:48. |