图搜插件demo

Posted yesyes

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图搜插件demo相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>

<head>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>
</head>
<style>
.box {
  display: inline-block;
  margin-right: 20px;
}

.demo {
  width: 70px;
  height: 70px;
  display: none;
  position: absolute;
  background-color: red;
}
</style>

<body>
  <div class="box">
    <img src="https://picsum.photos/200" >
  </div>
  <div class="box">
    <img src="https://picsum.photos/200" >
  </div>
  <div class="box">
    <img src="https://picsum.photos/200" >
  </div>
  <div class="box">
    <img src="https://picsum.photos/200" >
  </div>
  <div class="box">
    <img src="https://picsum.photos/200" >
  </div>
  <div class="box">
    <img src="https://picsum.photos/200" >
  </div>
  <script>
  function offset(el) {
    let top = el.offsetTop
    let left = el.offsetLeft
    while (el.offsetParent) {
      el = el.offsetParent
      top += el.offsetTop
      left += el.offsetLeft
    }
    return {
      left: left,
      top: top
    }
  }
  $(‘body‘).prepend(‘<div class="demo">good</div>‘)
  $(document).on(‘mouseenter‘, ‘img‘, function(e) {
    var x = e.target.getBoundingClientRect().x || Math.ceil(offset(e.target).left)
    var y = e.target.getBoundingClientRect().y || Math.ceil(offset(e.target).top)

    $(‘.demo‘).css({
      display: ‘block‘,
      left: x + ‘px‘,
      top: y + ‘px‘
    })
  })

  $(‘.demo‘).on(‘mousemove‘, function(e) {
    $(‘.demo‘).css({
      display: ‘block‘
    })
  })
  $(‘.demo‘).on(‘click‘, function(e) {
    $(‘.demo‘).css({
      display: ‘block‘
    })
    console.log(3)
  })
  $(document).on(‘mouseleave‘, ‘img‘, function(e) {
    $(‘.demo‘).css({
      display: ‘none‘
    })
  })
  </script>
</body>

</html>

以上是关于图搜插件demo的主要内容,如果未能解决你的问题,请参考以下文章

VIM 代码片段插件 ultisnips 使用教程

WordPress - 代码片段插件

VSCode插件开发全攻略代码片段设置自定义欢迎页

Wordpress - 将代码片段包含到布局的选定部分的插件

Word 文档的优秀代码片段工具或插件?

vim代码片段插件ultisnips的使用