Bạn được toimoihoc mời tham gia diễn đàn viết bài kiếm tiền VNO, bấm vào đây để đăng ký.

Admin

Nothing to lose.. your love to win..
23,516 ❤︎ Bài viết: 3752 Tìm chủ đề
381 9
Mã quảng cáo xuất hiện ở vị trí ngẫu nhiên bất kỳ trên trang web, màu + size chữ ngẫu nhiên

Demo: Việt Nam Overnight

HTML:
<!-- / CNG - ADS Top -->
<style>
  /* container phủ toàn viewport nhưng nằm dưới nội dung */
  #adsCloud {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
  }

  /* mỗi chữ */
  #adsCloud a {
    position: fixed;
    display: inline-block;
    text-decoration: none;
    padding: 2px 6px;
    line-height: 1.2;
    border-radius: 6px;
    white-space: nowrap;

    pointer-events: auto;
    user-select: none;
    transition: transform .25s ease;

    z-index: 0;
  }

  #adsCloud a:hover { transform: scale(1.15); }
</style>

<div id="adsCloud">
  <a href="https://dembuon.vn/threads/1526/">Đặt quảng cáo</a>
  <a href="https://vnbit.org/binance/">Binance</a>
  <a href="https://dembuon.vn/threads/2587/">kiếm tiền</a>
  <a href="https://dembuon.vn/threads/496/">thông báo</a>
  <a href="https://dembuon.vn/forums/game-show.35/">chơi game</a>
  <a href="https://play2048.io">2048</a>
  <a href="https://dembuon.vn/threads/1526/">text link</a>
  <a href="https://dembuon.vn/threads/459/">facebook</a>
  <a href="https://dembuon.vn/threads/481/">cách viết bài</a>
  <a href="https://dembuon.vn/threads/579/">thẻ điện thoại</a>
  <a href="https://dembuon.vn/threads/123023/">BOT giao dịch</a>
  <a href="https://vnbit.org/mexc/">MEXC</a>
  <a href="https://dembuon.vn/threads/1490/">tự sướng</a>
  <a href="https://dembuon.vn/threads/121678/">5 triệu</a>
</div>

<script>
(function () {
  const palette = [
    "#ff0000","#c0392b","#8e44ad","#a64dff","#0080ff","#2980b9",
    "#48b8d0","#16a085","#00b3b3","#00b359","#59b300","#ff4da6",
    "#ff8da1","#f39c12","#d35400","#b3b300","#ff8000","#b35900",
    "#0059b3","#7f8c8d"
  ];

  const GAP = 12;          // khoảng cách tối thiểu giữa các chữ (px)
  const MAX_TRIES = 600;   // số lần thử đặt vị trí cho mỗi chữ

  function rand(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  function getRandomColor() {
    return palette[Math.floor(Math.random() * palette.length)];
  }
  function getRandomSize() {
    return rand(11, 27);
  }

  function intersects(r1, r2) {
    return !(
      r1.right  + GAP < r2.left  ||
      r1.left   - GAP > r2.right ||
      r1.bottom + GAP < r2.top   ||
      r1.top    - GAP > r2.bottom
    );
  }

  function placeLinksNoOverlap() {
    const links = Array.from(document.querySelectorAll("#adsCloud a"));
    if (!links.length) return;

    const vw = window.innerWidth || document.documentElement.clientWidth;
    const vh = window.innerHeight || document.documentElement.clientHeight;
    const pad = 10;

    // set style trước để đo đúng kích thước
    links.forEach(a => {
      a.style.color = getRandomColor();
      a.style.fontSize = getRandomSize() + "px";
    });

    // lưu các rect đã đặt thành công
    const placed = [];

    links.forEach(a => {
      // reset tạm để đo width/height ổn định
      a.style.left = "0px";
      a.style.top = "0px";

      const baseRect = a.getBoundingClientRect();
      const w = baseRect.width;
      const h = baseRect.height;

      const maxX = Math.max(pad, vw - w - pad);
      const maxY = Math.max(pad, vh - h - pad);

      let ok = false;

      for (let i = 0; i < MAX_TRIES; i++) {
        const x = rand(pad, maxX);
        const y = rand(pad, maxY);

        const rect = {
          left: x,
          top: y,
          right: x + w,
          bottom: y + h
        };

        let collide = false;
        for (let j = 0; j < placed.length; j++) {
          if (intersects(rect, placed[j])) { collide = true; break; }
        }

        if (!collide) {
          a.style.left = x + "px";
          a.style.top = y + "px";
          placed.push(rect);
          ok = true;
          break;
        }
      }

      // nếu không tìm được chỗ trống (màn hình nhỏ / chữ nhiều) thì đặt đại nhưng giảm rủi ro
      if (!ok) {
        a.style.left = rand(pad, maxX) + "px";
        a.style.top  = rand(pad, maxY) + "px";
      }
    });
  }

  function init() {
    // 2 nhịp để font/layout ổn
    requestAnimationFrame(() => requestAnimationFrame(placeLinksNoOverlap));
  }

  window.addEventListener("load", init);
  window.addEventListener("resize", () => {
    // resize thì xếp lại
    placeLinksNoOverlap();
  });
})();
</script>
<!-- CNG - ADS Top / -->
 
Chỉnh sửa cuối:
Từ khóa: Sửa

Những người đang xem chủ đề này

Xu hướng nội dung

Back