If you noticed I have a ‘Back to top’ link appearing at the bottom right everytime you scroll down the page. Wonder how it was made? I’ll tell you. It’s quite simple. What you need is a div containing the text, apply some css and add an event using jQuery.
First, create the div:
Then add style to it, add this in your css file or inside <style> tag:
And last, the jQuery code:
There you have it! Simple isn’t it? :)
This works in Firefox 3.0.10 – 3.6.13, Internet Explorer 7 (Strict Mode) and 8, Google Chrome, jQuery 1.4.3.
Remember: On IE 7, your page needs to be at strict mode, just add a doctype at the top of your page:
Hope that helps :)
Sorry no IE 6 support and also I think it doesn’t work in Quirks Mode (will see if it’s possible) :(
Let me know if something is missing in the code sample, for some reason it always gets deleted every time I update the post in the visual editor.
Check a working sample here.
Comments closed due to spamming. If you have questions, please send me an email which can be found here.
原文取自:http://agyuku.net/2009/05/back-to-top-link-using-jquery/
參考來源:http://webdesignandsuch.com/10-jquery-back-to-top-link-solutions-for-websites/
First, create the div:
<div id="toTop">^ Back to Top</div> |
Then add style to it, add this in your css file or inside <style> tag:
#toTop { |
And last, the jQuery code:
<script src="path/to/js/jquery.js"></script> |
There you have it! Simple isn’t it? :)
This works in Firefox 3.0.10 – 3.6.13, Internet Explorer 7 (Strict Mode) and 8, Google Chrome, jQuery 1.4.3.
Remember: On IE 7, your page needs to be at strict mode, just add a doctype at the top of your page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
Hope that helps :)
Sorry no IE 6 support and also I think it doesn’t work in Quirks Mode (will see if it’s possible) :(
Let me know if something is missing in the code sample, for some reason it always gets deleted every time I update the post in the visual editor.
Check a working sample here.
Comments closed due to spamming. If you have questions, please send me an email which can be found here.
原文取自:http://agyuku.net/2009/05/back-to-top-link-using-jquery/
參考來源:http://webdesignandsuch.com/10-jquery-back-to-top-link-solutions-for-websites/