guide.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.clientX
  22. let mouse_y=event.clientY
  23. if ($(this).offset().left < $(document.body).width() / 2) {//左边
  24. $(this).children(".guide_contence").first().css("left",(mouse_x-20)+"px")
  25. $(this).children(".guide_contence").first().css("top",mouse_y+"px")
  26. $(this).children(".guide_contence").first().css("max-width",($(document.body).width()-mouse_x-20)+"px")
  27. } else {//右边
  28. $(this).children(".guide_contence").first().css("right",($(document.body).width()-mouse_x-20)+"px")
  29. $(this).children(".guide_contence").first().css("top",mouse_y+"px")
  30. $(this).children(".guide_contence").first().css("max-width",(mouse_x-20)+"px")
  31. }
  32. if ($(this).children(".guide_contence").first().html().length > 0) {
  33. return;
  34. }
  35. let gid = $(this).attr("gid");
  36. let url = $(this).attr("url");
  37. if (typeof url == "undefined" || url == "") {
  38. url = "../guide/get.php";
  39. }
  40. $.get(
  41. url,
  42. {
  43. id: gid,
  44. },
  45. function (data, status) {
  46. try {
  47. let jsonGuide = JSON.parse(data);
  48. $("guide[gid='" + jsonGuide.id + "']")
  49. .find(".guide_contence")
  50. .html(marked(jsonGuide.data));
  51. } catch (e) {
  52. console.error(e);
  53. }
  54. }
  55. );
  56. });
  57. }
  58. function guide_get(guide_id) {
  59. $.get(
  60. "../guide/get.php",
  61. {
  62. id: guide_id,
  63. },
  64. function (data, status) {
  65. try {
  66. let jsonGuide = JSON.parse(data);
  67. $("#guide_" + jsonGuide.id).html(marked(jsonGuide.data));
  68. } catch (e) {
  69. console.error(e);
  70. }
  71. }
  72. );
  73. }