javascript - How to fetch the background of DIV on a bottom layer with exact position using jQuery and CSS -
i'm looking make page has background gradient changes color every few seconds , blends between transitions. want apply effect on upper elements blocked element has solid background.
to give better example mean have attached simple mockup , understand i'm attempting do, i'm open suggestions.
the problem block contains black background png transparent used see black not gradient.
i'll include sample code far:
<body><!-- jquery script used add css background, easy stuff --> <div class="blackbox"> <div class="logo"><img src="#" alt=""></div> <hr class="h-line"> <div class="v-line"> </div> </div>
so i'm after either:
- a known jquery method obtain background image needs able refer of position of gradient inline background.
- a better solution getting work, please bare in mind page needs responsive use other methods since responsive can't think of any.
since ask alternatives jquery solutions
you play little margins
, box-shadow
, keyframe animations.
something in direction shape (depends on want part - add content ... , in way want responsive):
html:
<div class="wrapper"> <div class="header"><img src="http://i.imgur.com/cuboixr.png" alt="company name" /></div> <div class="content"></div> </div>
css:
body { background:orange; width:100%; height:100%; } .wrapper { width:40%; height:90%; border:30px solid #000; border-right-width:100px; border-bottom-width:100px; } .header { width:100%; border-bottom:10px solid transparent; -webkit-box-shadow: 0 30px 0 #000; -moz-box-shadow: 0 30px 0 #000; box-shadow: 0 30px 0 #000; } .header img { width:100%; } .content { width:95%; height:400px; background-color:#000; margin-top:30px; }
this way no javascript needed. , background can use linear gradient , animations css transitions or keyframe animations. need play lengths , adjust borders , box-shadows needs, maybe add @media queries responsiveness.
hope helps little in right direction =)
update:
i hoped gradients changing smaller problem ;-) silly me, sorry.
i elaborate css-only suggestion animation, can choose javascript slider background animation, if don't css3 solutions - although hot stuff ;-)
ok. so, add more fixed positioned elements gradient backgrounds (layer1 , layer2).
to have in direction in html now:
<div class="layer layer1"></div> <div class="layer layer2"></div> <div class="wrapper"> <div class="header"> <img src="http://newtpond.com/test/company-name.png" alt="company name" /> </div> <div class="content"></div> </div>
and add keyframe animation on them in css (here -webkit vendor prefix [probably cause lazy bum], hope can idea, , add others):
body { width:100%; height:100%; margin:0; padding:0; } /* animation */ .layer { position:fixed; width:100%; height:100%; } @-webkit-keyframes golayer1 { 0% { opacity:1; } 50% { opacity:0; } 100% { opacity:1; } } @-webkit-keyframes golayer2 { 0% { opacity:0; } 50% { opacity:1; } 100% { opacity:0; } } .layer1 { background: -webkit-linear-gradient(bottom, rgb(43, 70, 94) 29%, rgb(194, 41, 41) 65%, rgb(155, 171, 38) 83%); -webkit-animation: golayer1 5s infinite; } .layer2 { background: -webkit-linear-gradient(bottom, rgb(225, 202, 230) 29%, rgb(39, 163, 194) 65%, rgb(36, 124, 171) 83%); -webkit-animation: golayer2 5s infinite; } /* wrapper shape */ .wrapper { z-index:999; opacity:1; position:relative; width:40%; height:90%; border:30px solid #000; border-right-width:100px; border-bottom-width:100px; } .header { width:100%; border-bottom:10px solid transparent; -webkit-box-shadow: 0 30px 0 #000; -moz-box-shadow: 0 30px 0 #000; box-shadow: 0 30px 0 #000; } .header img { width:100%; } .content { width:95%; height:400px; background-color:#000; margin-top:28px; }
demo (tested in chrome 26 - looked cool =)
this can point according css-only approach. there still stuff modify , consider browser compatibility. alternative ... , step in direction html5 , css3 going (if want hot , cool ;-), hehe, sorry, silliness.
good luck!
update 2:
so, overcame laziness tiny bit , added more vendor prefixes top example (and of course can use image background):
demo
and here add example, using png image gradient, , sliding , down in background (as alternative):
Comments
Post a Comment