{"id":13508586,"url":"https://github.com/Jocs/view-image","last_synced_at":"2025-03-30T11:32:16.234Z","repository":{"id":98180976,"uuid":"145596228","full_name":"Jocs/view-image","owner":"Jocs","description":"An image viewer to zoom in and zoom out images.","archived":false,"fork":false,"pushed_at":"2018-08-27T14:18:29.000Z","size":195,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-24T21:38:41.545Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jocs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-08-21T17:19:59.000Z","updated_at":"2023-08-30T04:34:47.000Z","dependencies_parsed_at":"2023-06-29T18:15:59.154Z","dependency_job_id":null,"html_url":"https://github.com/Jocs/view-image","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jocs%2Fview-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jocs%2Fview-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jocs%2Fview-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jocs%2Fview-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jocs","download_url":"https://codeload.github.com/Jocs/view-image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246314011,"owners_count":20757450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:55.234Z","updated_at":"2025-03-30T11:32:15.770Z","avatar_url":"https://github.com/Jocs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/Jocs/img-viewer/blob/master/logo.png?raw=true\" alt=\"mark text\" width=\"100\" height=\"100\"\u003e\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eVIEW IMAGE\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cstrong\u003eA \u003ccode\u003etool\u003c/code\u003e to help you better preview your images\u003c/strong\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e\n    \u003ca href=\"https://github.com/jocs/img-viewer#features\"\u003e\n      Features\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/jocs/img-viewer#download\"\u003e\n      Download\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/jocs/img-viewer#guide\"\u003e\n      Guide\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/jocs/img-viewer#documents\"\u003e\n      Documents\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/jocs/img-viewer#integration\"\u003e\n      Integration\n    \u003c/a\u003e\n  \u003c/h3\u003e\n\u003c/div\u003e\n\n## Features\n\n* 支持图片放大、缩小、移动以及缩略图功能\n\n* 零依赖，并且支持 typescript\n\n* 能够很好的和 React、Vue、Anguar 前端框架整合\n\n## Download\n\n```sh\nnpm install -D view-image\n```\n\n## Guide\n\n在 html 文件中添加 `div#custom-id` 元素。\n\n```html\n\u003cdiv id=\"custom-id\"\u003e\u003c/div\u003e\n```\n\n在 javascript 文件中引入 `view-image`。\n\n```javascript\nimport ViewImage from 'view-image'\n\n// or add css in the html file\nimport 'view-image/lib/imgViewer.css'\n\nconst container = document.querySelector('#custom-id')\nconst imageViewer = new ViewImage(container, {\n  url: 'the/path/to/your/image/url.png'\n})\n```\n\n## Documents\n\n#### class：ViewImage\n\n构造函数，用于生成图片预览实例。用法如下：\n\n```javascript\nconst imageViewer = new ViewImage(container, options)\n```\n\n* container: **HTMLDivElement** 类型，用于设置图片预览的容器元素。\n\n* options：生成图片预览实例的配置项。\n\n| 选项               | 是否必选 | 类型       | 默认值   | 含义                                               |\n|:----------------:|:----:| -------- |:-----:|:------------------------------------------------:|\n| url              | 是    | string   | 无     | 预览图片 url                                         |\n| zoomValue        | 否    | number   | 100   | 初始图片放大倍数                                         |\n| snapView         | 否    | boolean  | true  | 是否显示缩略图                                          |\n| maxZoom          | 否    | number   | 1000  | 最大放大百分比                                          |\n| minZoom          | 否    | number   | 50    | 最小放大半分比                                          |\n| refreshOnResize  | 否    | boolean  | ture  | 窗口尺寸改变后是否调整图片大小                                  |\n| zoomOnMouseWheel | 否    | boolean  | true  | 通过鼠标滚轮调整图片缩放                                     |\n| beforeload       | 否    | function | noop* | 图片加载前的钩子函数*\u003cbr/\u003e () =\u003e {}                        |\n| loaded           | 否    | function | noop  | 图片成功加载的钩子函数\u003cbr/\u003e (image: HTMLImageElement) =\u003e {} |\n| failed           | 否    | function | noop  | 图片加载失败额钩子函数*\u003cbr/\u003e (error: Error) =\u003e {}           |\n\n**noop* is...\n\n```javascript\nconst noop = () =\u003e {}\n```\n\n#### instance methods\n\n**resetZoom**: \n\n将放大缩小倍数设置回初始值，也就是 options 中的 zoomValue 值。\n\nexample\n\n```javascript\nimageViewer.resetZoom()\n```\n\n**zoom**\n\n*public  zoom(value:  number  |  string): void  {}*\n\n调用该方法可以对图片进行放大缩小，第一个参数可以是一个keyValue，或者一个介于 minZoom 和 maxZoom 之间值。keyValue 包括如下：\n\n* original：将图片缩放为图片原始大小，但是不能够超出 minZoom ~ maxZoom 范围。\n\n* contain：容器整个包裹图片。\n\n* cover：图片覆盖整个容器。\n\n**zoomIn**\n\n*public  zoomIn()  {}*\n\n放大图片\n\n**zoomOut**\n\n*public  zoomOut()  {}*\n\n缩小图片\n\n**load**\n\n*public  load(imgUrl: string)  {}*\n\n更换预览图片\n\n## Integration\n\n**React**\n\n```javascript\nimport React from 'react'\nimport ImgViewer from 'view-image'\n\nclass ImageViewer extends React.Component {\n  componentDidMount() {\n    this.loadImage()\n  }\n  loadImage() {\n    const { container } = this\n    this.imageViewer = new ImgViewer(container, {\n      url: this.props.url,\n      zoomValue: 100,\n      beforeload() {\n        // set loading status\n      },\n      loaded() {\n        // toggle loading\n      },\n      failed() {\n        // set load fail status\n      }\n    })\n  }\n  render() {\n    return (\n      \u003cdiv\n      \tref={ref =\u003e {this.container = ref}}\n      \u003e\u003c/div\u003e\n    )\n  }\n}\n```\n\n**Vue**\n\n// 待补充\n\n**Angular**\n\n// 待补充\n\n## License\n\n**MIT**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJocs%2Fview-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJocs%2Fview-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJocs%2Fview-image/lists"}