Till toppen med ett klick
1. Klistra in detta längst ner i din stilmall:
#totop a
{
display
:
block
;
display
:
none
;
z-index
:
999
;
opacity: .
8
;
position
:
fixed
;
top
:
100%
;
margin-top
:
-80px
;
float
:
right
;
right
:
100px
;
-moz-border-radius:
24px
;
-webkit-border-radius:
24px
;
width
:
50px
;
line-height
:
48px
;
height
:
50px
;
padding
:
10px
;
background-color
:
#000
;
/* Du kan byta färg genom att du först tar bort #000 och skriver in den färg som ska visas när man inte hovrar */
font-size
:
24px
;
text-align
:
center
;
color
:
#fff
;
text-decoration
:
none
;
}
#totop a:hover {
background
:
#900
;
/*Färg när man hovrar! Byt ut #900 till en annan färg (om du vill) */
}
2. Klistra in denna i din kodmall, direkt under <body>
<
div
id
=
"top"
></
div
>
<
div
id
=
"totop"
><
a
href
=
"#top"
>↑</
a
></
div
>
<
script
type
=
"text/javascript"
>
$(function () {
var scroll_timer;
var displayed = false;
var $message = $('#totop a');
var $window = $(window);
var top = $(document.body).children(0).position(0).top;
$window.scroll(function () {
window.clearTimeout(scroll_timer);
scroll_timer = window.setTimeout(function () {
if($window.scrollTop() <= top)
{
displayed = false;
$message.fadeOut(500);
}
else if(displayed == false)
{
displayed = true;
$message.stop(true, true).show().click(function () { $message.fadeOut(500); });
}
}, 100);
});
});
</
script
>
3. Klart!
Kommentarer
Trackback