Difference between revisions of "Template:HKJS S/Javascript/Notebook"

 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
function expandall(){
 
function expandall(){
var value = ["229"];
+
var value = ["1","2","3","4","5","6","7","8","9","10","11","15","16"];
 
var i;
 
var i;
 
for (i = 0; i < value.length; i++){
 
for (i = 0; i < value.length; i++){
Line 10: Line 10:
 
}
 
}
 
function collapseall(){
 
function collapseall(){
var value = ["229"];
+
var value = ["1","2","3","4","5","6","7","8","9","10","11","15","16"];
 
var i;
 
var i;
 
for (i = 0; i < value.length; i++){
 
for (i = 0; i < value.length; i++){
Line 21: Line 21:
 
function expand(value){
 
function expand(value){
 
var a = value + "_btn";
 
var a = value + "_btn";
var btn = document.getElementById(a)
+
var btn = document.getElementById(a);
 
if(btn.innerHTML == "[Show]"){
 
if(btn.innerHTML == "[Show]"){
 
document.getElementById(value).style.display = "block";
 
document.getElementById(value).style.display = "block";
Line 34: Line 34:
  
 
function scrollFunction() {
 
function scrollFunction() {
     if (document.body.scrollTop > 1000 || document.documentElement.scrollTop > 1000) {
+
     if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
 
         document.getElementById("top_btn").style.display = "block";
 
         document.getElementById("top_btn").style.display = "block";
 
     } else {
 
     } else {
Line 40: Line 40:
 
     }
 
     }
 
}
 
}
 +
$(function() {
 +
$('.top_btn').click(function(e){
 +
 +
                    e.preventDefault();
 +
 +
                    $('html,body').animate({scrollTop: 0}, 300);
 +
 +
                });
 +
});

Latest revision as of 23:50, 17 October 2018

function expandall(){ var value = ["1","2","3","4","5","6","7","8","9","10","11","15","16"]; var i; for (i = 0; i < value.length; i++){ var a = value[i]; document.getElementById(a).style.display = "block"; var b = a + "_btn"; document.getElementById(b).innerHTML = "[Hide]"; } } function collapseall(){ var value = ["1","2","3","4","5","6","7","8","9","10","11","15","16"]; var i; for (i = 0; i < value.length; i++){ var a = value[i]; document.getElementById(a).style.display = "none"; var b = a + "_btn"; document.getElementById(b).innerHTML = "[Show]"; } } function expand(value){ var a = value + "_btn"; var btn = document.getElementById(a); if(btn.innerHTML == "[Show]"){ document.getElementById(value).style.display = "block"; document.getElementById(a).innerHTML = "[Hide]"; }else{ document.getElementById(value).style.display = "none"; document.getElementById(a).innerHTML = "[Show]"; } } window.onscroll = function() {scrollFunction()}; window.onload = function() {scrollFunction()};

function scrollFunction() {

   if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
       document.getElementById("top_btn").style.display = "block";
   } else {
       document.getElementById("top_btn").style.display = "none";
   }

}

$(function() {

$('.top_btn').click(function(e){

                   e.preventDefault();
                   $('html,body').animate({scrollTop: 0}, 300);
               });

});