-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tubingbing
committed
Jul 31, 2021
1 parent
fcdda83
commit 4185391
Showing
6 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ You can install it via npm: | |
npm i h5-imageviewer | ||
``` | ||
|
||
Or get it from CDN: | ||
[https://unpkg.com/[email protected]/umd/pobi-imageviewer.js](https://unpkg.com/[email protected]/umd/pobi-imageviewer.js) | ||
|
||
# Usage | ||
Show single image viewer | ||
```js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover"> | ||
<meta name="format-detection" content="telephone=no"> | ||
<title>H5 mobile image viewer</title> | ||
<script src="https://unpkg.com/[email protected]/umd/pobi-imageviewer.js"></script> | ||
<script src="./vconsole.min.js"></script> | ||
<script> | ||
// init vConsole | ||
var vConsole = new VConsole(); | ||
function showImage() { | ||
PobiImageViewer.showViewer( | ||
{src: 'http://localhost:8080/737a71084999bb9ee329f7afead08564.jpg'}, | ||
{ | ||
onPageChanged: pageIndex => { | ||
console.log('onPageChanged', pageIndex) | ||
}, | ||
} | ||
) | ||
} | ||
function showImageList() { | ||
PobiImageViewer.showImgListViewer( | ||
[ | ||
{src: 'http://localhost:8080/737a71084999bb9ee329f7afead08564.jpg'}, | ||
{src: 'http://localhost:8080/2e0036ab635f5b7dbcef2ca82b1cdca5.jpg'} | ||
], | ||
{ | ||
onPageChanged: pageIndex => { | ||
console.log('onPageChanged', pageIndex) | ||
}, | ||
onViewerHideListener: () => { | ||
console.log('image list viewer hide') | ||
}, | ||
} | ||
) | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<div id="root"> | ||
<button onclick="showImage()">Show image</button> | ||
<button onclick="showImageList()">Show image list</button> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const path = require('path') | ||
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') | ||
const { CleanWebpackPlugin } = require('clean-webpack-plugin') | ||
const nodeExternals = require('webpack-node-externals') | ||
const { version } = require('./package.json') | ||
|
||
module.exports = { | ||
mode: 'production', | ||
entry: './src/index.js', | ||
output: { | ||
path: path.resolve(__dirname, 'umd'), | ||
filename: "pobi-imageviewer.js", | ||
libraryExport: "default", | ||
libraryTarget: "umd", | ||
library: "PobiImageViewer" | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /.js$/, | ||
use: 'babel-loader' | ||
}, | ||
{ | ||
test: /.css$/, | ||
use: [ | ||
'style-loader', | ||
'css-loader' | ||
] | ||
}, | ||
{ | ||
test: /.less$/, | ||
use: [ | ||
'style-loader', | ||
'css-loader', | ||
'less-loader', | ||
{ | ||
// css3前缀自动补全 | ||
loader: 'postcss-loader', | ||
options: { | ||
plugins: () => [ | ||
require('autoprefixer')({}) | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
test: /.(jpg|png|gif|jpeg)$/, | ||
use: [ | ||
{ | ||
loader: 'file-loader', | ||
options: { | ||
limit: 10240, | ||
// 文件内容hash | ||
name: '[name]_[hash:8].[ext]' | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new CleanWebpackPlugin(), | ||
// css代码压缩 | ||
new OptimizeCSSAssetsPlugin({ | ||
assetNameRegExp: /\.css$/g, | ||
cssProcessor: require('cssnano') | ||
}) | ||
], | ||
devtool: 'source-map' | ||
} |