Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
7
7-Eleven
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
高淑倩
7-Eleven
Commits
da388df6
Commit
da388df6
authored
Sep 04, 2019
by
高淑倩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
轮播图自适应高度
parent
84e9bac4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
7 deletions
+48
-7
imageSwiper.js
src/component/imageSwiper/imageSwiper.js
+42
-2
imageSwiper.wxml
src/component/imageSwiper/imageSwiper.wxml
+6
-5
No files found.
src/component/imageSwiper/imageSwiper.js
View file @
da388df6
...
...
@@ -30,12 +30,52 @@ Component({
interval
:
5000
,
duration
:
1000
,
isAuthorization
:
false
,
// false 不显示 true 显示
baseImgUrl
:
''
},
baseImgUrl
:
''
,
maxHeight
:
0
,
padding
:
0
,
heights
:
[],
imageHeights
:
{},
// 记录所有图片的实际高度
},
observers
:
{
heights
:
function
(
heights
)
{
let
imageData
=
this
.
data
.
imageData
if
(
heights
.
length
===
imageData
.
length
)
{
let
maxHeight
=
Math
.
max
.
apply
(
null
,
heights
)
this
.
setData
({
maxHeight
,
})
wxService
.
nextTick
(()
=>
{
this
.
triggerEvent
(
'imageLoad'
,
{
maxHeight
,
windowWidth
:
this
.
data
.
windowWidth
},
{
bubbles
:
true
,
composed
:
true
}
)
})
}
},
},
/**
* 组件的方法列表
*/
methods
:
{
imageLoad
:
function
(
e
)
{
// 图片加载完成回调
let
heights
=
this
.
data
.
heights
let
id
=
e
.
target
.
id
var
imageWidth
=
e
.
detail
.
width
var
imageHeight
=
e
.
detail
.
height
var
ratio
=
imageWidth
/
imageHeight
var
sysRes
=
app
.
globalData
.
systemInfo
var
imageHeights
=
this
.
data
.
imageHeights
const
height
=
(
sysRes
.
windowWidth
-
(
this
.
data
.
padding
*
sysRes
.
windowWidth
)
/
750
)
/
ratio
heights
.
push
(
height
)
imageHeights
[
id
]
=
height
this
.
setData
({
imageHeights
:
imageHeights
,
windowWidth
:
sysRes
.
windowWidth
,
heights
})
},
preview
(
event
)
{
const
ev
=
event
.
currentTarget
.
dataset
;
let
curItemType
=
ev
.
item
...
...
src/component/imageSwiper/imageSwiper.wxml
View file @
da388df6
...
...
@@ -6,19 +6,20 @@
interval="{{interval}}"
circular="{{circular}}"
duration="{{duration}}"
style="height: {{maxHeight}}px;"
>
<block wx:for="{{imageData}}" wx:key="{{i
tem}}
">
<block wx:for="{{imageData}}" wx:key="{{i
ndex}}" wx:for-item="item
">
<swiper-item class="swiper-item">
<
image
<
view
wx:if="{{baseImgUrl}}"
src="{{item.imageUrl}}"
data-appid="{{item.link.appid}}"
data-path="{{item.link.url}}"
data-link="{{item.link}}"
data-item="{{item}}"
bindtap='preview'
class="slide-image"
/>
>
<image bindload="imageLoad" src="{{item.imageUrl}}" id="swiperImg{{index}}" mode="widthFix" class="slide-image" />
</view>
</swiper-item>
</block>
</swiper>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment