model.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <style>
  2. .draggable
  3. {
  4. cursor: pointer;
  5. }
  6. #bg {
  7. background-image:url('http://192.168.33.10/sellking/data/upload/1/2022/10/12/4d5893ad6c7f3ca0680c615e360a6041.png');
  8. background-repeat: no-repeat;
  9. background-size: contain;
  10. overflow: hidden;
  11. border: 1px solid;
  12. }
  13. #item {
  14. width: 600px;
  15. height: 300px;
  16. border: 1px solid #ddd;
  17. }
  18. .custom-context-menu {
  19. position: fixed;
  20. border: 1px solid #ccc;
  21. font-size: 15px;
  22. background: white;
  23. }
  24. .custom-context-menu {
  25. position: fixed;
  26. border: 1px solid #ccc;
  27. list-style: none;
  28. border-radius: 4px;
  29. box-shadow: 0px 2px 6px 2px #ddd;
  30. }
  31. .custom-context-menu li {
  32. padding: 8px 12px;
  33. border-bottom: 1px solid #f0f2f5;
  34. user-select: none;
  35. transition: all 0.1s;
  36. }
  37. .custom-context-menu li:last-child {
  38. border-bottom: none;
  39. }
  40. .custom-context-menu li:hover {
  41. cursor: pointer;
  42. background-color: #009688;
  43. color: #fff;
  44. }
  45. .custom-context-menu li:active {
  46. background-color: #009688;
  47. }
  48. .hidden {
  49. display: none;
  50. }
  51. </style>
  52. <div class="layui-fluid" style="padding: 0px;">
  53. <div id="bg">
  54. <div class="draggable" style="color:#fc0f0f;font-size: 16px;width: 50px;left:20px;top:20px;">微笑旋风</div>
  55. <div class="draggable" style="width: 50px;height:50px;">
  56. <img src="http://192.168.33.10/dreamland/data/upload/1/2020/07/06/58802289df6119614c2095230384c2cb.jpg" style="width: 50px;height:50px;">
  57. </div>
  58. </div>
  59. </div>
  60. <script id="url">var url = ""</script>
  61. <script>
  62. var p = 1;
  63. $( function() {
  64. var sort = $(".draggable").draggable({
  65. opacity: 0.7,
  66. containment: "#bg",
  67. addClasses: false,
  68. stop : function(event, ui) {
  69. var left = ui.position.left / p;
  70. var top = ui.position.top / p;
  71. $.post(url, {id:$(this).attr('data-id'),left:left,top:top}, function()
  72. {
  73. })
  74. }
  75. });
  76. $(".draggable").each(function() {
  77. let item = $(this).get(0);
  78. item.addEventListener('contextmenu', (e) => {
  79. e.preventDefault();
  80. let menu = item.getElementsByTagName('ul')[0]
  81. menu.style.top = `${e.clientY}px`;
  82. menu.style.left = `${e.clientX}px`;
  83. menu.classList.remove('hidden');
  84. let menuList = menu.getElementsByTagName('li')
  85. for (let menuItem of menuList) {
  86. }
  87. });
  88. item.addEventListener('click', () => {
  89. let menu = item.getElementsByTagName('ul')[0]
  90. menu.classList.add('hidden')
  91. })
  92. })
  93. $('#bg').each(function() {
  94. var img=$(this);
  95. var url=$(this).css('backgroundImage');
  96. s = url.match(/url\((.*?)\)/);
  97. url =s[1];
  98. if(url[0]=="\""){url = url.slice(1,-1)}
  99. $("<img/>").attr("src", url).load(function() {
  100. var realWidth = this.width;
  101. var realHeight = this.height;
  102. //如果真实的宽度大于浏览器的宽度就按照100%显示
  103. //var h = 500;
  104. //p = h / realHeight;
  105. var h = parseInt(realHeight*p);
  106. var w = parseInt(realWidth*p);
  107. img.css("height", h+"px");
  108. img.css("width",w+"px");
  109. $(".draggable").each(function() {
  110. var w = parseInt($(this).css("width")) * p;
  111. var h = parseInt($(this).css("height")) * p;
  112. $(this).css("width", w + 'px');
  113. $(this).css("height", h + 'px');
  114. if ($(this).find('img')) {
  115. $(this).find('img').css("width", w + 'px');
  116. $(this).find('img').css("height", h + 'px');
  117. }
  118. var l = parseInt($(this).css("left")) * p;
  119. var t = parseInt($(this).css("top")) * p;
  120. $(this).css("left", l + 'px');
  121. $(this).css("top", t + 'px');
  122. if ($(this).css("fontSize")) {
  123. var f = parseInt($(this).css("fontSize")) * p;
  124. $(this).css("fontSize", f + 'px');
  125. }
  126. $(this).show();
  127. });
  128. });
  129. });
  130. });
  131. </script>