mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 00:03:37 +08:00
Add pulsate/flash animations for drawing attention to posts
This commit is contained in:
parent
c35721d286
commit
a77303a473
|
@ -179,16 +179,33 @@ export default class StreamContent extends mixin(Component, evented) {
|
|||
scrollToItem($item, noAnimation) {
|
||||
var $container = $('html, body').stop(true);
|
||||
if ($item.length) {
|
||||
var scrollTop = $item.is(':first-child') ? 0 : $item.offset().top - this.getMarginTop();
|
||||
if (noAnimation) {
|
||||
$container.scrollTop(scrollTop);
|
||||
} else if (scrollTop !== $(document).scrollTop()) {
|
||||
$container.animate({scrollTop: scrollTop}, 'fast');
|
||||
var itemTop = $item.offset().top - this.getMarginTop();
|
||||
var itemBottom = itemTop + $item.height();
|
||||
var scrollTop = $(document).scrollTop();
|
||||
var scrollBottom = scrollTop + $(window).height();
|
||||
|
||||
// If the item is already in the viewport, just flash it, we don't need to
|
||||
// scroll anywhere.
|
||||
if (itemTop > scrollTop && itemBottom < scrollBottom) {
|
||||
this.flashItem($item);
|
||||
} else {
|
||||
var scrollTop = $item.is(':first-child') ? 0 : itemTop;
|
||||
if (noAnimation) {
|
||||
$container.scrollTop(scrollTop);
|
||||
} else if (scrollTop !== $(document).scrollTop()) {
|
||||
$container.animate({scrollTop: scrollTop}, 'fast', this.flashItem.bind(this, $item));
|
||||
} else {
|
||||
this.flashItem($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $container.promise();
|
||||
}
|
||||
|
||||
flashItem($item) {
|
||||
$item.addClass('flash').one('animationend webkitAnimationEnd', () => $item.removeClass('flash'));
|
||||
}
|
||||
|
||||
/**
|
||||
Find the DOM element of the item that is nearest to a post with a certain
|
||||
number. This will either be another post (if the requested post doesn't
|
||||
|
|
|
@ -166,6 +166,18 @@
|
|||
background: @fl-primary-color;
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes pulsate {
|
||||
0% {transform: scale(1)}
|
||||
50% {transform: scale(1.02)}
|
||||
100% {transform: scale(1)}
|
||||
}
|
||||
.item.pulsate {
|
||||
-webkit-animation: pulsate 1s ease-in-out;
|
||||
-webkit-animation-iteration-count: infinite;
|
||||
}
|
||||
.item.flash {
|
||||
-webkit-animation: pulsate 0.2s ease-in-out;
|
||||
-webkit-animation-iteration-count: 1;
|
||||
}
|
||||
.post-header {
|
||||
margin-bottom: 10px;
|
||||
|
|
Loading…
Reference in New Issue
Block a user