Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
349d097e
Commit
349d097e
authored
Dec 19, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update slideIn and slideOut to use `requestAnimationFrame`
For smoother animations.
parent
7ae735c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
39 deletions
+41
-39
src/utils.js
src/utils.js
+41
-39
No files found.
src/utils.js
View file @
349d097e
...
...
@@ -73,16 +73,6 @@
});
};
function
calculateSlideStep
(
height
)
{
if
(
height
>
100
)
{
return
10
;
}
else
if
(
height
>
50
)
{
return
5
;
}
else
{
return
1
;
}
}
function
calculateElementHeight
(
el
)
{
/* Return the height of the passed in DOM element,
* based on the heights of its children.
...
...
@@ -186,7 +176,7 @@
return
_
.
includes
(
el
.
classList
,
className
);
};
u
.
slideOut
=
function
(
el
,
duration
=
100
0
)
{
u
.
slideOut
=
function
(
el
,
duration
=
25
0
)
{
/* Shows/expands an element by sliding it out of itself
*
* Parameters:
...
...
@@ -200,10 +190,10 @@
reject
(
new
Error
(
err
));
return
;
}
let
interval_
marker
=
el
.
getAttribute
(
'
data-slider-marker
'
);
if
(
interval_
marker
)
{
const
marker
=
el
.
getAttribute
(
'
data-slider-marker
'
);
if
(
marker
)
{
el
.
removeAttribute
(
'
data-slider-marker
'
);
window
.
c
learInterval
(
interval_
marker
);
window
.
c
ancelAnimationFrame
(
marker
);
}
const
end_height
=
calculateElementHeight
(
el
);
if
(
window
.
converse_disable_effects
)
{
// Effects are disabled (for tests)
...
...
@@ -217,34 +207,40 @@
return
;
}
const
step
=
calculateSlideStep
(
end_height
),
interval
=
end_height
/
duration
*
step
;
let
h
=
0
;
interval_marker
=
window
.
setInterval
(
function
()
{
h
+=
step
;
if
(
h
<
end_height
)
{
el
.
style
.
height
=
h
+
'
px
'
;
const
steps
=
duration
/
17
;
// We assume 17ms per animation which is ~60FPS
let
height
=
0
;
function
draw
()
{
height
+=
end_height
/
steps
;
if
(
height
<
end_height
)
{
el
.
style
.
height
=
height
+
'
px
'
;
el
.
setAttribute
(
'
data-slider-marker
'
,
window
.
requestAnimationFrame
(
draw
)
);
}
else
{
// We recalculate the height to work around an apparent
// browser bug where browsers don't know the correct
// offsetHeight beforehand.
el
.
removeAttribute
(
'
data-slider-marker
'
);
el
.
style
.
height
=
calculateElementHeight
(
el
)
+
'
px
'
;
el
.
style
.
overflow
=
""
;
el
.
style
.
height
=
""
;
window
.
clearInterval
(
interval_marker
);
resolve
();
}
},
interval
);
}
el
.
style
.
height
=
'
0
'
;
el
.
style
.
overflow
=
'
hidden
'
;
el
.
classList
.
remove
(
'
hidden
'
);
el
.
classList
.
remove
(
'
collapsed
'
);
el
.
setAttribute
(
'
data-slider-marker
'
,
interval_marker
);
el
.
setAttribute
(
'
data-slider-marker
'
,
window
.
requestAnimationFrame
(
draw
)
);
});
};
u
.
slideIn
=
function
(
el
,
duration
=
80
0
)
{
u
.
slideIn
=
function
(
el
,
duration
=
25
0
)
{
/* Hides/collapses an element by sliding it into itself. */
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
_
.
isNil
(
el
))
{
...
...
@@ -258,30 +254,36 @@
el
.
style
.
height
=
""
;
return
resolve
();
}
let
interval_
marker
=
el
.
getAttribute
(
'
data-slider-marker
'
);
if
(
interval_
marker
)
{
const
marker
=
el
.
getAttribute
(
'
data-slider-marker
'
);
if
(
marker
)
{
el
.
removeAttribute
(
'
data-slider-marker
'
);
window
.
c
learInterval
(
interval_
marker
);
window
.
c
ancelAnimationFrame
(
marker
);
}
let
h
=
el
.
offsetHeight
;
const
step
=
calculateSlideStep
(
h
),
interval
=
h
/
duration
*
step
;
const
original_height
=
el
.
offsetHeight
,
steps
=
duration
/
17
;
// We assume 17ms per animation which is ~60FPS
let
height
=
original_height
;
el
.
style
.
overflow
=
'
hidden
'
;
interval_marker
=
window
.
setInterval
(
function
()
{
h
-=
step
;
if
(
h
>
0
)
{
el
.
style
.
height
=
h
+
'
px
'
;
function
draw
()
{
height
-=
original_height
/
steps
;
if
(
height
>
0
)
{
el
.
style
.
height
=
height
+
'
px
'
;
el
.
setAttribute
(
'
data-slider-marker
'
,
window
.
requestAnimationFrame
(
draw
)
);
}
else
{
el
.
removeAttribute
(
'
data-slider-marker
'
);
window
.
clearInterval
(
interval_marker
);
el
.
classList
.
add
(
'
collapsed
'
);
el
.
style
.
height
=
""
;
resolve
();
}
},
interval
);
el
.
setAttribute
(
'
data-slider-marker
'
,
interval_marker
);
}
el
.
setAttribute
(
'
data-slider-marker
'
,
window
.
requestAnimationFrame
(
draw
)
);
});
};
...
...
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