9. 返回页面顶部功能
1. $(document).ready(function() { 2. $('a[href*=#]').click(function() { 3. if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 4. && location.hostname == this.hostname) { 5. var $target = $(this.hash); 6. $target = $target.length && $target 7. || $('[name=' + this.hash.slice(1) +']'); 8. if ($target.length) { 9. var targetOffset = $target.offset().top; 10. $('html,body') 11. .animate({scrollTop: targetOffset}, 900); 12. return false; 13. } 14. } 15. }); 16. // how to use 17. // place this where you want to scroll to 18. <A name=top></A> 19. // the link 20. <A href="#top">go to top</A> 21. }); |
10.获得鼠标指针XY值
1. $(document).ready(function() { 2. $().mousemove(function(e){ 3. //display the x and y axis values inside the div with the id XY 4. $('#XY').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY); 5. }); 6. // how to use 7. <DIV id=XY></DIV> 8. 9. }); |
11. 验证元素是否为空
1. $(document).ready(function() { 2. if ($('#id').html()) { 3. // do something 4. } 5. }); |
12. 替换元素
1. $(document).ready(function() { 2. $('#id').replaceWith(' 3. <DIV>I have been replaced</DIV> 4. 5. '); 6. }); |
13. jQuery延时加载功能
1. $(document).ready(function() { 2. window.setTimeout(function() { 3. // do something 4. }, 1000); 5. }); |
14. 移除单词功能
1. $(document).ready(function() { |
相关阅读: