0

Not sure what the syntax should be for setting the background image and gradient (so that I can darken the image)

I can set the background image but not sure how I can set the linear gradient

  holder.style.background = 'url(' + event.target.result + ') no-repeat';
  holder.style.backgroundSize = 'cover';
  holder.style.backgroundlinearGradient = 'rgba(0, 0, 0, 0.7)'  //this doesn't work

Also, can I combine more than one property in style.background to set all 3 size and gradient and image in one line?

Note that I cannot use jquery and want to do this by setting dom attributes if possible.

6
  • I would try this without javaScript first. ie just html and css Commented Dec 26, 2014 at 17:20
  • why not use jquery css() to set all at once Commented Dec 26, 2014 at 17:21
  • can't install jquery installed in this environment and this has to be set using javascript as an asynchronous response to an event. Commented Dec 26, 2014 at 17:28
  • 1
    linearGradient is not a CSS property. It is a value of the background property. Perhaps you are looking for the filter property if you want to darken the image. Commented Dec 26, 2014 at 17:40
  • use jQuery and add/remove a class where u define your css-values. Commented Dec 26, 2014 at 17:48

1 Answer 1

4

Now I'm just a js newbie, however, I believe you can combine all your background properties into one larger declaration, or add them through some vars that contain info regarding your css, such as:

var some_fancy_gradient = 'linear-gradient(red, blue)';
var some_fancy_image = 'your url'
yourelement.style.background = 'url('+some_fancy_image+') center center / cover no-repeat,'+some_fancy_gradient+' no-repeat';

See Demo

Don't know if this is what your looking for, but may point you in the right direction.

Also, some documentation:

Sign up to request clarification or add additional context in comments.

6 Comments

That js fiddle is pretty awesome, great santa BTW
BTW, what's the syntax for concatenating all those properties, do they have to be in a certain order, when to use slash or commas - is that documented somewhere?
Thanks, glad to help out! Ill post in a sec some resources
There, hope that helps out
Put all the styling in a css class and just add or remove the className property in javascript.Seems pretty clean.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.