Skip to content

Commit 6be89fe

Browse files
committed
修改横竖屏比例问题
1 parent 62960f3 commit 6be89fe

File tree

4 files changed

+29
-48
lines changed

4 files changed

+29
-48
lines changed

example/pdfh5-vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build": "node build/build.js"
1111
},
1212
"dependencies": {
13-
"pdfh5": "^1.2.13",
13+
"pdfh5": "^1.2.14",
1414
"vue": "^2.5.2"
1515
},
1616
"devDependencies": {

example/test/js/pdfh5.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; (function (g, fn) {
2-
var version = "1.2.13";
2+
var version = "1.2.14";
33
console.log("The latest version and API of pdfh5 from: https://github.com/gjTool/pdfh5 (pdfh5.js: " + version + ")")
44
if (typeof require !== 'undefined') {
55
if (g.$ === undefined) {
@@ -1021,13 +1021,13 @@
10211021
'max-width': viewport.width,
10221022
"max-height": viewport.height,
10231023
"min-height": viewport.height * scale + 'px'
1024-
}).attr("data-height", viewport.height * scale)
1024+
}).attr("data-scale", viewport.width / viewport.height)
10251025
self.viewer[0].appendChild(container);
10261026
self.cache[pageNum + ""].container = container;
10271027
self.cache[pageNum + ""].scaledViewport = scaledViewport;
10281028
var sum = 0, containerH = self.container.height();
10291029
self.pages = self.viewerContainer.find('.pageContainer');
1030-
if(options.resize){
1030+
if (options.resize) {
10311031
self.resize()
10321032
}
10331033
if (self.pages && options.lazy) {
@@ -1097,7 +1097,7 @@
10971097
}
10981098
$(container).css({
10991099
"min-height": $(svg).height() + 'px'
1100-
}).attr("data-height", $(svg).height())
1100+
})
11011101
var time = new Date().getTime();
11021102
var arr1 = self.eventType["render"];
11031103
if (arr1 && arr1 instanceof Array) {
@@ -1162,12 +1162,12 @@
11621162
obj2.src = obj2.canvas.toDataURL("image/jpeg");
11631163
img.src = obj2.src;
11641164
container.appendChild(img);
1165-
img.onload = function(){
1165+
img.onload = function () {
11661166
$(container).css({
11671167
"min-height": img.height + 'px'
1168-
}).attr("data-height", img.height)
1168+
})
11691169
}
1170-
1170+
11711171
var time = new Date().getTime();
11721172
var arr1 = self.eventType["render"];
11731173
if (arr1 && arr1 instanceof Array) {
@@ -1221,32 +1221,22 @@
12211221
},
12221222
resize: function () {
12231223
var self = this;
1224-
var timer;
12251224
if (self.resizeEvent) {
12261225
return
12271226
}
12281227
self.resizeEvent = true;
12291228
if (self.pages) {
1230-
var height = self.pages.attr("data-height");
12311229
$(window).on("resize", function () {
12321230
var winWidth = $(window).width();
12331231
if (self.winWidth === winWidth) {
1234-
self.pages.css({
1235-
"min-height": height + 'px'
1236-
})
1237-
console.log(height)
1232+
12381233
} else {
1239-
self.pages.css({
1240-
"min-height": 'auto'
1241-
})
1242-
clearTimeout(timer)
1243-
timer = setTimeout(function () {
1244-
var h = self.pages.height();
1245-
self.pages.css({
1246-
"min-height": h + 'px'
1234+
self.pages.each(function (i, item) {
1235+
var w = $(item).width(), s = $(item).attr("data-scale");
1236+
$(item).css({
1237+
"min-height": w/s + 'px'
12471238
})
1248-
console.log(h)
1249-
}, 0)
1239+
})
12501240
}
12511241
})
12521242
}

js/pdfh5.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; (function (g, fn) {
2-
var version = "1.2.13";
2+
var version = "1.2.14";
33
console.log("The latest version and API of pdfh5 from: https://github.com/gjTool/pdfh5 (pdfh5.js: " + version + ")")
44
if (typeof require !== 'undefined') {
55
if (g.$ === undefined) {
@@ -1021,13 +1021,13 @@
10211021
'max-width': viewport.width,
10221022
"max-height": viewport.height,
10231023
"min-height": viewport.height * scale + 'px'
1024-
}).attr("data-height", viewport.height * scale)
1024+
}).attr("data-scale", viewport.width / viewport.height)
10251025
self.viewer[0].appendChild(container);
10261026
self.cache[pageNum + ""].container = container;
10271027
self.cache[pageNum + ""].scaledViewport = scaledViewport;
10281028
var sum = 0, containerH = self.container.height();
10291029
self.pages = self.viewerContainer.find('.pageContainer');
1030-
if(options.resize){
1030+
if (options.resize) {
10311031
self.resize()
10321032
}
10331033
if (self.pages && options.lazy) {
@@ -1097,7 +1097,7 @@
10971097
}
10981098
$(container).css({
10991099
"min-height": $(svg).height() + 'px'
1100-
}).attr("data-height", $(svg).height())
1100+
})
11011101
var time = new Date().getTime();
11021102
var arr1 = self.eventType["render"];
11031103
if (arr1 && arr1 instanceof Array) {
@@ -1162,12 +1162,12 @@
11621162
obj2.src = obj2.canvas.toDataURL("image/jpeg");
11631163
img.src = obj2.src;
11641164
container.appendChild(img);
1165-
img.onload = function(){
1165+
img.onload = function () {
11661166
$(container).css({
11671167
"min-height": img.height + 'px'
1168-
}).attr("data-height", img.height)
1168+
})
11691169
}
1170-
1170+
11711171
var time = new Date().getTime();
11721172
var arr1 = self.eventType["render"];
11731173
if (arr1 && arr1 instanceof Array) {
@@ -1221,32 +1221,22 @@
12211221
},
12221222
resize: function () {
12231223
var self = this;
1224-
var timer;
12251224
if (self.resizeEvent) {
12261225
return
12271226
}
12281227
self.resizeEvent = true;
12291228
if (self.pages) {
1230-
var height = self.pages.attr("data-height");
12311229
$(window).on("resize", function () {
12321230
var winWidth = $(window).width();
12331231
if (self.winWidth === winWidth) {
1234-
self.pages.css({
1235-
"min-height": height + 'px'
1236-
})
1237-
console.log(height)
1232+
12381233
} else {
1239-
self.pages.css({
1240-
"min-height": 'auto'
1241-
})
1242-
clearTimeout(timer)
1243-
timer = setTimeout(function () {
1244-
var h = self.pages.height();
1245-
self.pages.css({
1246-
"min-height": h + 'px'
1234+
self.pages.each(function (i, item) {
1235+
var w = $(item).width(), s = $(item).attr("data-scale");
1236+
$(item).css({
1237+
"min-height": w/s + 'px'
12471238
})
1248-
console.log(h)
1249-
}, 0)
1239+
})
12501240
}
12511241
})
12521242
}

pdf.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
//当前默认优先获取浏览器地址栏?file=后面的地址,如果地址栏没有,再拿配置项的pdfurl或者data来渲染pdf
3333
//优先顺序: ?file= > pdfurl > data
3434
var pdfh5 = new Pdfh5('#demo', {
35-
pdfurl: "git.pdf"
35+
pdfurl: "git.pdf",
36+
lazy:true
3637
});
3738

3839
// window.onorientationchange = function () {

0 commit comments

Comments
 (0)