- This topic has 19 replies, 3 voices, and was last updated 6 years, 11 months ago by David.
-
AuthorPosts
-
September 18, 2017 at 3:10 pm #387646DavidStaffCustomer Support
Hi Tom / Leo,
any way to adjust the starting Y position of the background image?
thanks
David
September 18, 2017 at 3:19 pm #387647LeoStaffCustomer SupportHi David,
In the page header? I think that causes some conflict with the parallax script.
Take a look at Tom’s explanation here: https://generatepress.com/forums/topic/reporting-bug-with-page-headers/
Let us know if this helps 🙂
September 18, 2017 at 3:36 pm #387654DavidStaffCustomer SupportHi Leo,
thanks but that’s not the issue. I am using GP headers on product pages which is so cool. The parallax positions the images with a Y of 0;
The problem i have is the product featured images are square transparent background PNG’s so theres dead space top and bottom which means some images are effectively cropped off at the bottom.
I need to move the background-position-Y to negative value to counter act this but cant because the JS overrides this.
Can’t crop the images either as they are required as so for the shop.
Current workaround is to scale down the images which helps but doesn’t fix all….thanks
David
September 18, 2017 at 7:37 pm #387718TomLead DeveloperLead DeveloperHmm, I’m not sure the current parallax JS could handle a negative starting point. I’ll look into it – it may be possible. It may be necessary on those specific products to deactivate the parallax script.
September 18, 2017 at 8:11 pm #387732DavidStaffCustomer SupportHi Tom,
o.k – is it possible to kill the vertical movement on the background image? What i really want is the image to remain fixed on all devices hence the need for the JS…..
David
September 18, 2017 at 10:41 pm #387760TomLead DeveloperLead DeveloperTry this:
.generate-content-header { background-position: center top !important; background-attachment: fixed; }
September 19, 2017 at 2:56 am #387863DavidStaffCustomer SupportHi Tom – sorry I think you misunderstood that method doesn’t work on iOS Safari ☹️
September 19, 2017 at 6:49 pm #388400TomLead DeveloperLead DeveloperAh, right. Perhaps this will help?: https://stackoverflow.com/questions/23236158/how-to-replicate-background-attachment-fixed-on-ios
September 19, 2017 at 7:25 pm #388411DavidStaffCustomer SupportHi Tom, thanks for looking into this for me, i have tried these workarounds before on other experiments with varying degrees of success. I’ll give them another go on this one which is using the GP Headers.
Alternatively can the parallax be slowed down to the point where it’s almost stationery?
September 19, 2017 at 8:44 pm #388426TomLead DeveloperLead DeveloperYou can try playing with this filter: https://docs.generatepress.com/article/generate_page_header_parallax_speed/
September 20, 2017 at 5:47 am #388668DavidStaffCustomer SupportThank you Tom – brilliant i added a conditional for
is_product
so it only effects my product headers to slow the rate accordingly. Reading the github on this module i notice you can pass data attributes such as PosX and PosY which is analogous with the CSS property so it should be able to handle a negative number.Is there a function to write these values in?
Sorry i feel like i’m asking a little too much
September 20, 2017 at 8:45 pm #389147TomLead DeveloperLead DeveloperCurrently there aren’t any filters for those values.
You can of course, build your own script if you’re interested?
September 21, 2017 at 3:22 am #389313DavidStaffCustomer SupportThanks Tom – if only I knew where to begin! But willing to give it a go
September 22, 2017 at 2:28 pm #390257DavidStaffCustomer SupportHi Tom, I almost nailed the issue by removing the full width header which causes the scaling issues but then had to resort to a 100vh height which lead to problems with sticking my price bar to the bottom of the header. lol
Can you share the function for the parallax speed? maybe i can hack it to apply to the positioning
September 22, 2017 at 11:16 pm #390359TomLead DeveloperLead DeveloperGive this a shot.
First, we’ll remove the current script:
add_action( 'wp_enqueue_scripts', 'tu_switch_ph_parallax', 100 ); function tu_switch_ph_parallax() { wp_dequeue_script( 'generate-page-header-parallax' ); wp_enqueue_script( 'custom-page-header-parallax', 'URL TO YOUR SCRIPT', array(), GENERATE_PAGE_HEADER_VERSION, true ); }
And here’s the script, which you would link to in the function above and adjust as needed:
function generate_parallax_element( selector, context ) { context = context || document; var elements = context.querySelectorAll( selector ); return Array.prototype.slice.call( elements ); } window.addEventListener( "scroll", function() { var scrolledHeight= window.pageYOffset; generate_parallax_element( ".parallax-enabled" ).forEach( function( el, index, array ) { var limit = el.offsetTop + el.offsetHeight; if( scrolledHeight > el.offsetTop && scrolledHeight <= limit ) { el.style.backgroundPositionY = ( scrolledHeight - el.offsetTop ) / el.getAttribute( 'data-parallax-speed' ) + "px"; } else { el.style.backgroundPositionY = "0"; } }); });
-
AuthorPosts
- You must be logged in to reply to this topic.