guide.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. function guide_init() {
  2. $("guide").each(function () {
  3. if ($(this).attr("init") != "1") {
  4. if ($(this).text().length > 0) {
  5. $(this).css("background", "unset");
  6. }
  7. if ($(this).offset().left < $(document.body).width() / 2) {
  8. $(this).append('<div class="guide_contence"></div>');
  9. //$(this).append('<div class="guide_contence left" style="right: max('+($(this).offset().left+$(this).width()+30-$(document.body).width())+'px,-20em);left: -5px;"></div>');
  10. //$(this).after().css("left", +($(this).offset().left-$(this).parent().offset().left)+"px");
  11. } else {
  12. //$(this).append('<div class="guide_contence"></div>');
  13. $(this).append('<div class="guide_contence right" style="right:-5px"></div>');
  14. //$(this).append('<div class="guide_contence right" style="left: '+($(this).parent().offset().left-$(this).offset().left)+'px;right:-5px"></div>');
  15. //$(this).after().css("right", ($(this).parent().offset().left+$(this).parent().width()+13-$(this).offset().left-$(this).width())+"px");
  16. }
  17. $(this).attr("init", "1");
  18. }
  19. });
  20. $("guide").mouseenter(function (event) {
  21. let mouse_x=event.pageX
  22. let mouse_y=event.pageY
  23. $(this).children(".guide_contence").first().css("top","15px")
  24. $(this).children(".guide_contence").first().css("width","max-content")
  25. //if ($(this).offset().left < $(document.body).width() / 2) {//左边
  26. if (mouse_x < ($(document.body).width() / 2)) {//左边
  27. $(this).children(".guide_contence").first().css("left","-10px")
  28. $(this).children(".guide_contence").first().css("max-width",("calc(100vw - "+mouse_x+"px - 20px"))
  29. } else {//右边
  30. //$(this).children(".guide_contence").first().css("right",($(document.body).width()-mouse_x-20)+"px")
  31. //$(this).children(".guide_contence").first().css("top",mouse_y+"px")
  32. $(this).children(".guide_contence").first().css("max-width",(mouse_x-20)+"px")
  33. $(this).children(".guide_contence").first().css("right","-10px")
  34. }
  35. if ($(this).children(".guide_contence").first().html().length > 0) {
  36. return;
  37. }
  38. let gid = $(this).attr("gid");
  39. let url = $(this).attr("url");
  40. if (typeof url == "undefined" || url == "") {
  41. url = "../guide/get.php";
  42. }
  43. $.get(
  44. url,
  45. {
  46. id: gid,
  47. },
  48. function (data, status) {
  49. try {
  50. let jsonGuide = JSON.parse(data);
  51. $("guide[gid='" + jsonGuide.id + "']")
  52. .find(".guide_contence")
  53. .html(marked(jsonGuide.data));
  54. } catch (e) {
  55. console.error(e);
  56. }
  57. }
  58. );
  59. });
  60. }
  61. function guide_get(guide_id) {
  62. $.get(
  63. "../guide/get.php",
  64. {
  65. id: guide_id,
  66. },
  67. function (data, status) {
  68. try {
  69. let jsonGuide = JSON.parse(data);
  70. $("#guide_" + jsonGuide.id).html(marked(jsonGuide.data));
  71. } catch (e) {
  72. console.error(e);
  73. }
  74. }
  75. );
  76. }