Участник:MailGik/hilarious.js — различия между версиями
Материал из Hilarious Wiki
MailGik (обсуждение | вклад) |
MailGik (обсуждение | вклад) |
||
Строка 3: | Строка 3: | ||
var snowId = document.getElementById("footer"); | var snowId = document.getElementById("footer"); | ||
var solfId = document.createElement("a"); | var solfId = document.createElement("a"); | ||
− | solfId.setAttribute("id"," | + | solfId.setAttribute("id","scroll-top"); |
solfId.setAttribute("title","Наверх"); | solfId.setAttribute("title","Наверх"); | ||
snowId.appendChild(solfId); | snowId.appendChild(solfId); | ||
− | function | + | function scrollTop(){ |
$(window).scroll(function(e) { | $(window).scroll(function(e) { | ||
//If the scroll bar at the top of more than 200 elements | //If the scroll bar at the top of more than 200 elements | ||
if($(window).scrollTop()>200) | if($(window).scrollTop()>200) | ||
− | $("# | + | $("#scroll-top").fadeIn(100);//In a second interval in the id=scroll-top element |
else | else | ||
− | $("# | + | $("#scroll-top").fadeOut(100);//In a second interval fade out the elements of id=scroll-top |
}); | }); | ||
}; | }; | ||
$(function(){ | $(function(){ | ||
//Click back on top of the elements | //Click back on top of the elements | ||
− | $("# | + | $("#scroll-top").click(function(e) { |
//Return to top with second interval | //Return to top with second interval | ||
$('body,html').animate({scrollTop:0},100); | $('body,html').animate({scrollTop:0},100); | ||
}); | }); | ||
− | + | scrollTop();//The fade in and fade out back to the top element | |
}); | }); |
Версия 17:29, 19 августа 2016
/* Добавляет кнопку "Вверх" слева */
var snowId = document.getElementById("footer");
var solfId = document.createElement("a");
solfId.setAttribute("id","scroll-top");
solfId.setAttribute("title","Наверх");
snowId.appendChild(solfId);
function scrollTop(){
$(window).scroll(function(e) {
//If the scroll bar at the top of more than 200 elements
if($(window).scrollTop()>200)
$("#scroll-top").fadeIn(100);//In a second interval in the id=scroll-top element
else
$("#scroll-top").fadeOut(100);//In a second interval fade out the elements of id=scroll-top
});
};
$(function(){
//Click back on top of the elements
$("#scroll-top").click(function(e) {
//Return to top with second interval
$('body,html').animate({scrollTop:0},100);
});
scrollTop();//The fade in and fade out back to the top element
});