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

Redundant/unnecessary code overriding CSS properties on background image #21

Open
jtsimoes opened this issue Jul 30, 2020 · 1 comment

Comments

@jtsimoes
Copy link

jtsimoes commented Jul 30, 2020

Hi!

Since in your .css you told us to add this:

.parallax__container .parallax {
/* can be put in a seperate class for better control */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/* --------------------------- */

Why then you have an if on your .js doing the same thing?

if (parallax[i].classList.length === 1 && parallax[i].classList[0] === 'parallax') {
parallax[i].style.backgroundRepeat = 'no-repeat';
parallax[i].style.backgroundPosition = 'center';
parallax[i].style.backgroundSize = 'cover';
}

If no other class than .parallax is specified, adding this CSS it's kinda unnecessary code because the .parallax class already have it, no?


Also, this piece of code takes away the possibility of having repeated backgrounds with other size than cover and with a custom position (different then center). For instance, it's useful when you have small size GIFs or patterns and you need to repeat the background to fill the parallax:

Background image:
https://i.imgur.com/o4hJvT7.gif

Code:

<section style="min-height: 100vh;">
	(...)
	<div class="parallax" data-parallax-image="/img/403.gif" style="background-repeat: repeat; background-size: 500px;">
	</div>
</section>

Parallax before removing the if (if's code replacing the inline style I put on div):
image

Parallax after removing the if (same code it works now):
image

(The parallax effect was working on both, trust me)

@marrio-h
Copy link
Owner

Thank you @jtsimoes I will look into it (an all other comments) soon. If you want, feel free to make a pull request😊

All of your feedback is invaluable

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

2 participants