From 9d318fb64dd2767e2586b2391e4e157a4e59e730 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 15 Jul 2022 12:36:39 +1200 Subject: [PATCH] Remove setting of default position when toggling parallax --- packages/block-library/src/cover/edit/index.js | 4 +++- packages/block-library/src/cover/save.js | 4 +++- packages/block-library/src/cover/shared.js | 3 +-- packages/block-library/src/cover/style.scss | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/cover/edit/index.js b/packages/block-library/src/cover/edit/index.js index ee9536aa1ed2b5..7f5cdb8345f1db 100644 --- a/packages/block-library/src/cover/edit/index.js +++ b/packages/block-library/src/cover/edit/index.js @@ -161,7 +161,9 @@ function CoverEdit( { const backgroundImage = url ? `url(${ url })` : undefined; - const backgroundPosition = mediaPosition( focalPoint ); + const backgroundPosition = focalPoint + ? mediaPosition( focalPoint ) + : undefined; const bgStyle = { backgroundColor: overlayColor.color }; const mediaStyle = { diff --git a/packages/block-library/src/cover/save.js b/packages/block-library/src/cover/save.js index 6dbf67a3684bd3..717299c0fded3b 100644 --- a/packages/block-library/src/cover/save.js +++ b/packages/block-library/src/cover/save.js @@ -77,7 +77,9 @@ export default function save( { attributes } ) { const backgroundImage = url ? `url(${ url })` : undefined; - const backgroundPosition = mediaPosition( focalPoint ); + const backgroundPosition = focalPoint + ? mediaPosition( focalPoint ) + : undefined; const classes = classnames( { diff --git a/packages/block-library/src/cover/shared.js b/packages/block-library/src/cover/shared.js index c28f099b485235..5198a730c3f4d3 100644 --- a/packages/block-library/src/cover/shared.js +++ b/packages/block-library/src/cover/shared.js @@ -21,10 +21,9 @@ export const VIDEO_BACKGROUND_TYPE = 'video'; export const COVER_MIN_HEIGHT = 50; export const COVER_MAX_HEIGHT = 1000; export const COVER_DEFAULT_HEIGHT = 300; -export const DEFAULT_FOCAL_POINT = { x: 0.5, y: 0.5 }; export const ALLOWED_MEDIA_TYPES = [ 'image', 'video' ]; -export function mediaPosition( { x, y } = DEFAULT_FOCAL_POINT ) { +export function mediaPosition( { x, y } ) { return `${ Math.round( x * 100 ) }% ${ Math.round( y * 100 ) }%`; } diff --git a/packages/block-library/src/cover/style.scss b/packages/block-library/src/cover/style.scss index 957cfc5d4e23a3..50c9b80297fa38 100644 --- a/packages/block-library/src/cover/style.scss +++ b/packages/block-library/src/cover/style.scss @@ -201,6 +201,8 @@ video.wp-block-cover__video-background { &.has-parallax { background-attachment: fixed; + background-position: 50%; + background-size: cover; // Mobile Safari does not support fixed background attachment properly. // See also https://stackoverflow.com/questions/24154666/background-size-cover-not-working-on-ios