model.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <style>
  2. .draggable
  3. {
  4. cursor: pointer;
  5. }
  6. #bg {
  7. background-image:url('http://192.168.33.10/dreamland/data/upload/1/2020/11/09/d06b800db5022f9ae73dfa4de559eec7.jpg');
  8. background-repeat: no-repeat;
  9. background-size: contain;
  10. overflow: hidden;
  11. }
  12. </style>
  13. <div class="layui-fluid" style="padding: 0px;">
  14. <div id="bg">
  15. <div class="draggable" style="color:#fc0f0f;font-size: 16px;width: 50px;left:20px;top:20px;">微笑旋风</div>
  16. <div class="draggable" style="width: 50px;height:50px;">
  17. <img src="http://192.168.33.10/dreamland/data/upload/1/2020/07/06/58802289df6119614c2095230384c2cb.jpg" style="width: 50px;height:50px;">
  18. </div>
  19. </div>
  20. </div>
  21. <script id="url">var url = ""</script>
  22. <script>
  23. var p = 1;
  24. $( function() {
  25. var sort = $(".draggable").draggable({
  26. opacity: 0.7,
  27. containment: "#bg",
  28. addClasses: false,
  29. stop : function(event, ui) {
  30. var left = ui.position.left / p;
  31. var top = ui.position.top / p;
  32. $.post(url, {id:$(this).attr('data-id'),left:left,top:top}, function()
  33. {
  34. })
  35. }
  36. });
  37. $('#bg').each(function() {
  38. var img=$(this);
  39. var url=$(this).css('backgroundImage');
  40. s = url.match(/url\((.*?)\)/);
  41. url =s[1];
  42. if(url[0]=="\""){url = url.slice(1,-1)}
  43. $("<img/>").attr("src", url).load(function() {
  44. var realWidth = this.width;
  45. var realHeight = this.height;
  46. //如果真实的宽度大于浏览器的宽度就按照100%显示
  47. //var h = 500;
  48. //p = h / realHeight;
  49. var h = parseInt(realHeight*p);
  50. var w = parseInt(realWidth*p);
  51. img.css("height", h+"px");
  52. img.css("width",w+"px");
  53. $(".draggable").each(function() {
  54. var w = parseInt($(this).css("width")) * p;
  55. var h = parseInt($(this).css("height")) * p;
  56. $(this).css("width", w + 'px');
  57. $(this).css("height", h + 'px');
  58. if ($(this).find('img')) {
  59. $(this).find('img').css("width", w + 'px');
  60. $(this).find('img').css("height", h + 'px');
  61. }
  62. var l = parseInt($(this).css("left")) * p;
  63. var t = parseInt($(this).css("top")) * p;
  64. $(this).css("left", l + 'px');
  65. $(this).css("top", t + 'px');
  66. if ($(this).css("fontSize")) {
  67. var f = parseInt($(this).css("fontSize")) * p;
  68. $(this).css("fontSize", f + 'px');
  69. }
  70. $(this).show();
  71. });
  72. });
  73. });
  74. });
  75. </script>