common.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. $(function(){
  2. var rightNavMove = function(){
  3. var mousex = 0, mousey = 0;
  4. var divLeft = 0, divTop = 0, left = 0, top = 0;
  5. document.getElementById("right-nav").addEventListener('touchstart', function(e){
  6. var offset = $(this).offset();
  7. divLeft = parseInt(offset.left,10);
  8. divTop = parseInt(offset.top,10);
  9. mousey = e.touches[0].pageY;
  10. mousex = e.touches[0].pageX;
  11. });
  12. document.getElementById("right-nav").addEventListener('touchmove', function(event){
  13. event.preventDefault();
  14. left = event.touches[0].pageX-(mousex-divLeft);
  15. top = event.touches[0].pageY-(mousey-divTop)-$(window).scrollTop();
  16. if(top < 1){
  17. top = 1;
  18. }
  19. if(top > $(window).height()-(50+$(this).height())){
  20. top = $(window).height()-(50+$(this).height());
  21. }else if(top < 40)
  22. top = 40;
  23. $(this).css({'top':top + 'px','left':left + 'px', 'position':'fixed'});
  24. return false;
  25. });
  26. document.getElementById("right-nav").addEventListener('touchend', function(event){
  27. if(left > $(window).width()/2)
  28. {
  29. left = $(window).width()-$(this).width()-5;
  30. }else{
  31. left = 5;
  32. }
  33. if ((divLeft == left && divTop == top) || (top == 0 )) {
  34. return false;//$(this).trigger('click');
  35. }else{
  36. $(this).css({'top':top + 'px','left':left + 'px', 'position':'fixed'});
  37. }
  38. return false;
  39. });
  40. };
  41. rightNavMove();
  42. });