Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default 25px on background position's y axis #89

Open
daviedR opened this issue Apr 12, 2014 · 21 comments
Open

Default 25px on background position's y axis #89

daviedR opened this issue Apr 12, 2014 · 21 comments

Comments

@daviedR
Copy link

daviedR commented Apr 12, 2014

Hi Mark,

First I really love this plugin. And it's the first time I use it for my project. But I got an issue with the plugin. Here's a short story what I did with your plugin.

I create a section at the very top. This section will have parallax background via data-stellar-background-ratio="0.5". I set the section's style to set

background-size: cover;
background-position: center center;
background-attachment: fixed
/* this will create the background image size follow the viewport's size, and it's needed. */

and I set the stellar options like this:

$.stellar({
    horizontalScrolling: false,
    responsive: true,
});

And I fire the script on document.ready. I noticed that when stellar is initiated, it set the background-position to 50% 25px. I don' understand why it gives default 25px on the background-position's y axis.

And then after the window is loaded, as I set the responsive to true, the plugin will calculate the background position. It sets to 50% 50%. But when I scrolled down the page and scrolled back to the very top. It sets to 50% 25px again.

It turns out that I set the ratio to 0.5 it will give you 25px and if I set the ratio to 0.25 I will have 12.5px.

My questions:

  • Why the plugin give non-zero initial y axis? I think it should be 0px on y axis position.
  • Why your responsive mode reset it to 50% 50%. I believe it should be 50% 0px. This will create a flash which is not good on the eye. Because on ready state you set it to 50% 25px and then on window loaded you set it back to 50% 50%.

Thanks

@mikegrantme
Copy link

I'm having the same issue. Hope to see an answer to your question as well! +1 for loving this plugin.

@ianpatrickhines
Copy link

I’m seeing the same issue, except for me I’m seeing background-postition: 25px 0;. Otherwise, it’s the same as being described above (i.e., if I halve the ratio to 0.25 I get background-position: 12.5px 0;). Seems buggy to me, but I cannot be sure.

@frontend-3
Copy link

Same issue

@OriginalEXE
Copy link

Hey folks, I managed to fix it.

The issue happens when browser returns % as a current background position, script parses it as an integer (basically ignores % so 50% === 50px) causing this issue to happen.

To fix, open jquery.stellar.js and change line 435 to look like this:

startingBackgroundPositionLeft: (isNaN(parseInt(backgroundPosition[0], 10))||-1!==backgroundPosition[0].indexOf('%') ? 0 : parseInt(backgroundPosition[0], 10)),

and line 436 like this:

startingBackgroundPositionTop: (isNaN(parseInt(backgroundPosition[1], 10))||-1!==backgroundPosition[1].indexOf('%') ? 0 : parseInt(backgroundPosition[1], 10)),

Hopefully it works for you too :)

@yjsoon
Copy link

yjsoon commented Jun 16, 2014

Just writing here to confirm @OriginalEXE's solution works. Thanks very much.

@camslice
Copy link

Nice one @OriginalEXE

@dutchiexl
Copy link

Fix didn't work for me, any other suggestions? This only happens in IE for me

@dutchiexl
Copy link

It seems, for me, backgroundPosition[1] is not set.

This gives an undifened on startingValueTop: backgroundPosition[1] line 443.

This fixes it:startingValueTop: isNaN(parseInt(backgroundPosition[1], 10) ? 0 : backgroundPosition[1],

@igorlaszlo
Copy link

After corrected originalEXE's proposition, i do not have 25px/25px space BUT : i have background-position: 50% 50% and background-size: cover like daviedR, and when i start to scroll, the background jumps to background-position: 50% 0px. If i do not use background-size: cover, it does not matter, the background jumps back to top 0px in any way... Some suggestion ?
@daviedR : how did you do it ?
(PS: This plugin would be even more popular with some more explications... a year ago i wanted to use but it did not work for me because i could not get any explication, not even on Stackoverflow forum... however, it is a good plugin !)

@igorlaszlo
Copy link

@dutchiexl : i guess you did not close your code, my dreamweaver signs an error... when i close it like this : startingValueTop: isNaN(parseInt(backgroundPosition[1], 10) ? 0 : backgroundPosition[1]), it does not solve my problem (that i have set background-position 50% 50% but it jumps back to 0px to top when scrolling)...

@igorlaszlo
Copy link

Also i want to tell to @OriginalEXE that the js file was not updated with the fixed codes in the website : http://markdalgleish.com/projects/stellar.js/ where i downloaded the docs some days ago...

@andrewmy
Copy link

Thank you @OriginalEXE!

@OriginalEXE
Copy link

Hi @igorlaszlo, I am aware of that. I am not the author of this script so I have no power to apply the fix to the it, I submitted a pull request for the original author but this script is no longer maintained.

@dephora
Copy link

dephora commented Feb 3, 2015

Is this fix still working on current versions of Chrome? I seem to be having the issue on Chrome 40, though I had not tried it in previous builds. It works fine in FireFox.

@OriginalEXE
Copy link

Should work in version 40 too, do you have any live url I could test? Also, are you sure you are loading the correct version and have cleared the cache?

@crcommons
Copy link

Unfortunately this didn't work for me either. When the page loads the background-position is set to 50% 50%. On scroll, it changes to 50% 37.5px. After making the changes to the Stellar.js file, it loads with 50% 50%, but now changes to 50% 0px. I'm not sure what to do...

Any help would be much appreciated!

@ghost
Copy link

ghost commented May 7, 2015

@crcommons I think you should find yourself something else to create the parallax scrolling effect since stellar.js just ignores the unit and treat everything as px and the author isn't planning to do any maintenance.

@bitkidd
Copy link

bitkidd commented May 10, 2015

This worked for me.

background-size: cover;
background-position: 0 0;
background-attachment: fixed;
background-repeat: no-repeat;

@ExDementia
Copy link

@keeross That worked for me perfectly, thanks!

@Arcrammer
Copy link

@OriginalEXE Wow. Great job.

@ctrl-d
Copy link

ctrl-d commented Aug 9, 2017

i simply added verticalOffset: 50, and it works just fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests