MediaWiki:Test.js: различия между версиями

Страница интерфейса MediaWiki
Нет описания правки
Метка: отменено
Нет описания правки
Метка: отменено
Строка 3: Строка 3:
     position:'fixed', bottom:'20px', right:'20px',
     position:'fixed', bottom:'20px', right:'20px',
     padding:'5px 10px', background:'#444', color:'#fff',
     padding:'5px 10px', background:'#444', color:'#fff',
     cursor:'pointer', borderRadius:'5px'
     cursor:'pointer', borderRadius:'5px', zIndex:9999
   }).hide().appendTo('body');
   }).appendTo('body');


   $(window).scroll(function() {
   var menu = $('<div></div>').css({
     if ($(this).scrollTop() > 200) btn.fadeIn(); else btn.fadeOut();
    position:'fixed', bottom:'60px', right:'20px',
    maxHeight:'300px', overflow:'auto',
    padding:'5px 10px', background:'#fff', border:'1px solid #444',
    borderRadius:'5px', display:'none', zIndex:9999
  }).appendTo('body');
 
  $('h1, h2, h3').each(function() {
    var id = $(this).attr('id');
     if (!id) {
      id = 'hdr-' + Math.random().toString(36).substr(2,5);
      $(this).attr('id', id);
    }
    var link = $('<div>'+$(this).text()+'</div>').css({
      cursor:'pointer', padding:'2px 0'
    }).appendTo(menu);
    link.click(function() {
      $('html, body').animate({scrollTop:$('#'+id).offset().top}, 500);
      menu.hide();
    });
   });
   });


   btn.click(function() {
   btn.click(function() {
     $('html, body').animate({scrollTop:0}, 500);
     menu.toggle();
   });
   });
});
});

Версия от 19:17, 23 августа 2025

$(function() {
  var btn = $('<div>▲ Наверх</div>').css({
    position:'fixed', bottom:'20px', right:'20px',
    padding:'5px 10px', background:'#444', color:'#fff',
    cursor:'pointer', borderRadius:'5px', zIndex:9999
  }).appendTo('body');

  var menu = $('<div></div>').css({
    position:'fixed', bottom:'60px', right:'20px',
    maxHeight:'300px', overflow:'auto',
    padding:'5px 10px', background:'#fff', border:'1px solid #444',
    borderRadius:'5px', display:'none', zIndex:9999
  }).appendTo('body');

  $('h1, h2, h3').each(function() {
    var id = $(this).attr('id');
    if (!id) {
      id = 'hdr-' + Math.random().toString(36).substr(2,5);
      $(this).attr('id', id);
    }
    var link = $('<div>'+$(this).text()+'</div>').css({
      cursor:'pointer', padding:'2px 0'
    }).appendTo(menu);
    link.click(function() {
      $('html, body').animate({scrollTop:$('#'+id).offset().top}, 500);
      menu.hide();
    });
  });

  btn.click(function() {
    menu.toggle();
  });
});