• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Zufällige positionierung durch Javascript. Verbindung zu Body ist vergeblich.

Status
Für weitere Antworten geschlossen.

Cola

Neues Mitglied
Hallo Zusammen,

ich versuche vergeblich in der folgenden html Datei die Position left und top durch zufällige Zahlen, via Javascript zu manipulieren.
Leider kenne ich mich auch nicht so besonders mit dem programmieren aus. Nach zwei Wochen suchen habe ich die Hoffnung aufgegeben es in Google zu finden.


  1. <!DOCTYPE html>
  2. <html>
  3. <script src="https://vuejs.org/js/vue.js"></script>

  4. <head lang="en">
  5. <meta charset="UTF-8">
  6. <title>Redeem Overlay</title>
  7. <script src="../API_Key.js"></script>
  8. <style>
  9. html,
  10. body {
  11. height: 100%;
  12. }

  13. html {
  14. display: table;
  15. }

  16. body#body {
  17. display: table-cell;
  18. position: fixed;
  19. left: 150px; <- diese Position und top darunter sollen zufällige Zahlen bekommen
  20. top: 200px;
  21. }

  22. h2 {
  23. color: white;
  24. text-shadow: -1px -1px 0 #000,
  25. 1px -1px 0 #000,
  26. -1px 1px 0 #000,
  27. 1px 1px 0 #000;
  28. }

  29. .fade-enter-active,
  30. .fade-leave-active {
  31. transition: opacity .5s;
  32. }

  33. .fade-enter,
  34. .fade-leave-to
  35. /* .fade-leave-active below version 2.1.8 */
  36. {
  37. opacity: 0;
  38. }
  39. </style>
  40. </head>

  41. <body id="body">

  42. <div class="item" id="app">
  43. <client-component inline-template>
  44. <div>
  45. <link v-bind:href="fontfamilyurl" rel="stylesheet" type="text/css">
  46. <transition name="fade">
  47. <div v-if="fade">
  48. <img v-bind:src="imageurl">
  49. <h2 v-bind:style="{ color: fontcolor, fontSize: fontsize + 'px', fontFamily: fontfamily, width: width + 'px', 'word-wrap': wordwrap, 'margin-top': margintop + 'px', 'margin-left': marginleft + 'px', 'line-height': lineheight}"
  50. v-html="text">
  51. </h2>
  52. </div>
  53. </transition>
  54. </div>
  55. </client-component>
  56. </div>

  57. </body>
  58. <script src="async.js"></script>
  59. <script src="newclient.js"></script>

  60. <script>
  61. new Vue({
  62. el: '#app',
  63. });
  64. </script>

  65. <script> <- dieses Script soll die Zufälligen Zahlen ausgeben.
  66. $(document).ready(function() {
  67. var bodyWidth = document.body.clientWidth
  68. var bodyHeight = document.body.clientHeight;

  69. $('#body').each(function(idx, img) { <- mit #body wollte ich auf die Zeile 19. zugreifen
    ?(
  70. var randPosX = Math.floor((Math.random() * 1700));
  71. var randPosY = Math.floor((Math.random() * 800));
  72. console.log(randPosY);
  73. $(img).css('left', randPosX);
  74. $(img).css('top', randPosY);
  75. posLog.innerHTML = posXY
  76. });
  77. });
  78. </script>

  79. </html>
Würde mich freuen, wenn mir jemand helfen kann
^^
 
Werbung:
Da reicht Vanilla-JS völlig aus. Gibt es Voraussetzungen oder würde da nichts dagegen sprechen?
 
Werbung:
Es war ein Versuch mit jquery (script 76.), leider habe ich es nicht hinbekommen. Die Lösung kann auch anders aussehen. Wichtig ist nur für mich, dass zufällige Zahlen da stehen wenn die Seite aufgebaut wird :smile:
 
Werbung:
Status
Für weitere Antworten geschlossen.
Zurück
Oben