互动游戏网页抽签版

这是一个介绍如何创建互动游戏网页抽签版的博客。网页包含随机选择图片的功能,图片显示游戏内容,与文字选择无关,并伴有计时器。用户可以查看网页效果以及获取源码进行进一步定制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

互动游戏网页抽签版

  互动游戏,可以随机选择图片(图片上带有游戏内容),与所选择的字无关。

网页效果

东拼西凑-before
点击前
东拼西凑-after
点击后
  屏幕左下角显示游戏图片编号,游戏内容选择与所选的文字无关,带有时钟,可以设置计时任务。网页源码见InteractiveGame

代码实现

html部分:

  <div class="main">
    <h1>东拼西凑</h1>
    <div id="content">
      <div id="littleBoxes" class="littleBoxes">
        <div id="item11">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
        <div id="item12">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
        <div id="item13">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
        <div id="item21">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
        <div id="item22">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
        <div id="item23">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
        <div id="item31">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
        <div id="item32">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
        <div id="item33">
          <a class="title" href=""></a>
          <div class="boxcontent"><img /></div>
        </div>
      </div>
    </div>
    <div id="clock" class="clock-container">
      <div style="position: absolute; top: 270px; left: 30px;">
        <p class="clock">
          <a id="hours"></a>:
          <a id="min"></a>:
          <a id="sec"></a>
        </p>
      </div>
    </div>
    <div id="topbox"></div>
    <footer>
      <h1 style="font-size: 24px; color: #fff;">出品人:<a href="mailto:jinliwei1990@outlook.com" style="color: #fff;">金礼伟</a>&nbsp;游戏编号:<a id="gameid">1</a></h1>
    </footer>
  </div>

js代码,可以修改格子大小:

$(function() {
  var w = 200; //littleBoxes width
  var h = 200; //littleBoxes height
  $('#item11').css({ 'top': 0, 'left': 0 });
  $('#item12').css({ 'top': 0, 'left': w + 5 });
  $('#item13').css({ 'top': 0, 'left': (w + 5) * 2 });
  $('#item21').css({ 'top': h + 5, 'left': 0 });
  $('#item22').css({ 'top': h + 5, 'left': w + 5 });
  $('#item23').css({ 'top': h + 5, 'left': (w + 5) * 2 });
  $('#item31').css({ 'top': (h + 5) * 2, 'left': 0 });
  $('#item32').css({ 'top': (h + 5) * 2, 'left': w + 5 });
  $('#item33').css({ 'top': (h + 5) * 2, 'left': (w + 5) * 2 });

  /* object to save the initial positions of each box */
  var divinfo = { "initial": [] };
  /* index of the selected / clicked box */
  var current = -1;

  /* we save the index,top and left of each one of the boxes */
  $('#littleBoxes > div').each(function() {
    var $this = $(this);
    var initial = {
      'index': $this.index(),
      'top': $this.css('top'),
      'left': $this.css('left')
    };
    divinfo.initial.push(initial);
  });

  /* clcik event for the anchors inside of the boxes */
  $('#littleBoxes a').bind('click', function(e) {
    /* top block disable the click function顶层遮挡层,在动画期间遮挡点击动作 */
    $('#topbox').css({ "width": document.documentElement.clientWidth, "height": document.documentElement.clientHeight, "background-color": "#000", "opacity": "0", "z-index": "999" });
    /* timer,execute function after interval time定时器,到时间间隔后执行函数 */
    window.setTimeout(function() { $('#topbox').css({ "width": "0px", "height": "0px" }); }, 1000);

    var $this = $(this);
    var $currentBox = $this.parent();
    /* set a z-index lower than all the other boxes,
    to see the other boxes animation on the top*/
    $currentBox.css('z-index', '1');

    /* if we are clicking on a expanded box : */
    if (current == $currentBox.index()) {
      /* put it back (decrease width,height, and set the top and left like it was before).
      the previous positions are saved in the divinfo obj*/
      $currentBox.stop().animate({
        'top': divinfo.initial[$currentBox.index()].top,
        'left': divinfo.initial[$currentBox.index()].left,
        'width': w + 'px',
        'height': h + 'px'
      }, 800, 'easeOutBack').find('.boxcontent').fadeOut();

      $('#littleBoxes > div').not($currentBox).each(function() {
        var $ele = $(this);
        var elemTop = divinfo.initial[$ele.index()].top;
        var elemLeft = divinfo.initial[$ele.index()].left;
        $ele.stop().show().animate({
          'top': elemTop,
          'left': elemLeft,
          'opacity': 1
        }, 800);
      });
      current = -1;
    }
    /* if we are clicking on a small box : */
    else {
      /* randomly animate all the other boxes.
      Math.floor(Math.random()*601) - 150 gives a random number between -150 and 450.
      This range is considering the initial lefts/tops of the elements. It's not the exact right
      range, since we would have to calculate the range based on each one of the boxes. Anyway, it
      fits our needs...
      */
      $('#littleBoxes > div').not($currentBox).each(function() {
        var $ele = $(this);
        $ele.stop().animate({
          'top': (Math.floor(Math.random() * 600) - 100) + 'px',
          'left': (Math.floor(Math.random() * 900) - 450) + 'px',
          'opacity': 0
        }, 800, function() {
          $(this).hide();
        });
      });

      /* expand the clicked one. Also, fadeIn the content (boxcontent)
      if you want it to fill the space of the littleBoxes container,
      then these are the right values */
      var newwidth = w * 3 + 12;
      var newheight = h * 3 + 12;
      $currentBox.stop().animate({
        'top': '0px', //0px
        'left': '0px', //0px
        'width': newwidth + 'px',
        'height': newheight + 'px'
      }, 800, 'easeOutBack', function() {
        current = $currentBox.index();
        $(this).find('.boxcontent').fadeIn();
      });

      /* random a number, change the image src and display the number */
      var ch = 1 + Math.floor(Math.random() * 9);
      $currentBox.find('img').attr('src', './img/' + ch + '.jpg'); //find the img in clicked currentBox and change it's src
      $('#gameid').text(ch); //display the random number
    }
    e.preventDefault();
  });
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值