Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. <div name="top">
  2. <!-- some code -->
  3. <a class="myLinkToTop" href="#bot">Click</a>
  4. <!-- some code -->
  5. <div name="bot">
  6.  
  7. <script>
  8. $(".myLinkToTop").click(function(){
  9. $("a.myLinkToTop").attr("href","#top");
  10. });
  11. </script>
  12.  
  13. $(".myLinkToTop").click(function(e){
  14. e.preventDefault();
  15. window.location.href = this.href;
  16. this.href = this.hash === "#top" ? "#bot" : "#top";
  17. });
  18.  
  19. $(".myLinkToTop").on("click", function () {
  20. var $this = $(this), // cache "this as a jQuery object"
  21. href = $this.attr("href");
  22.  
  23. if (href === "#bot") {
  24. setTimeout(function () {
  25. $this.attr("href", "#top");
  26. }, 100);
  27. } else {
  28. setTimeout(function () {
  29. $this.attr("href", "#bot");
  30. }, 100);
  31. }
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement