Skip to content

Picture 壁纸

自定义样式

移步到 CSS Part

基本用法

查看代码
css
.main-container {
  width: 100%;
  height: 30rem;

  overflow: auto;
}

html

html
<div class="main-container">
  <gr-picture></gr-picture>
</div>

js

js
// 测试数据
const mockData = [
  "../../assets/imgs/other/WIKI攻略.png",
  "../../assets/imgs/other/官方周边.png",
  "../../assets/imgs/other/官方漫画.png",
  "../../assets/imgs/other/官方周边.png",
  "../../assets/imgs/other/WIKI攻略.png",
];

// 模拟数据获取
const mockFetchData = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({ data: mockData });
    }, 200);
  });
};

const container = document.querySelector("gr-picture");
mockFetchData().then((res) => {
  container.pictures = res.data; // 为该元素设置图片列表
});

无限加载

TIP

当传入的所有图片渲染完成之后,再次触底,将会触发 gr-picture-render-finished 事件。仅需在 document 对象上添加监听事件即可。

js
document.addEventListener("gr-picture-render-finished", () => {
  console.log("finished");
});
查看代码

html

html
<div class="main-container"></div>

js

js
const mockData = [
  "../../../../assets/imgs/other/WIKI攻略.png",
  "../../../../assets/imgs/other/官方周边.png",
  "../../../../assets/imgs/other/官方漫画.png",
  "../../../../assets/imgs/other/官方周边.png",
  "../../../../assets/imgs/other/WIKI攻略.png",
  "../../../../assets/imgs/home-bg.png",
  "../../../../assets/imgs/other/WIKI攻略.png",
  "../../../../assets/imgs/other/官方周边.png",
  "../../../../assets/imgs/other/官方漫画.png",
  "../../../../assets/imgs/other/官方周边.png",
  "../../../../assets/imgs/other/WIKI攻略.png",
  "../../../../assets/imgs/other/WIKI攻略.png",
];

const container = document.querySelector(".main-container");
window.$GrPictureInfinateScrollRenderer({ root: container, urls: mockData });

Attributes

参数说明类型可选值默认值
pictures图片链接Array--

Gr-picture CSS Part

用法可参考 MDN ::part()伪类

参数说明
container根容器
  • 左边部分

参数说明
left-wrap左边部分根容器
left-top-img上面的图片
left-bottom-img下面的图片
  • 中间部分

参数说明
center-wrap中间部分根容器
center-img中间的图片
  • 右边部分

参数说明
right-wrap右边部分根容器
right-top-img上面的图片
right-bottom-img下面的图片

Gr-sg-img CSS Part

参数说明
container根容器
search-icon搜索图标的容器
search-glass搜索图标的镜框
search-handgrip搜索图标的手柄
img图片