jquery or javascript active element on foreground, lock background? - javascript

I have a layer that is presented by a logic var.
that layer is just a hidden div - how do I make it so the layer is the only element that can be interacted with on the page when it is visible?
thanks!
Update:
used a full size div in the background with a transparent gif - works in firefox, but not IE - thoughts?
#overlay {
background-image: url('../images/transparent.gif');
width:100%;
height:100%;
z-index:8999;
display:none;
margin-top: 0;
margin-left:0;
position:fixed;
}

The basic approach is to put a semi-transparent element over your whole page, but under your modal window that contains your focus element. JQuery doesn't have this built in, so you can either create your own using that approach or use a JQuery plugin.
UPDATE:
Here's a fiddle based on the comment discussion. I've tested this and it works in IE8, Firefox 3.5.15, and Chrome 12.0.742.112.
HTML:
<div class="overlay"></div>
<div>test</div>
<input/>
<div class="modalWindow ">
foo:
<input/>
</div>
CSS:
.overlay {
opacity:.1;
filter:alpha(opacity=10);
background-color: black;
width:100%;
height:100%;
z-index:8999;
margin-top: 0;
margin-left:0;
position:fixed;
}
.modalWindow {
z-index:9000;
position: fixed;
background-color: white;
top: 20px;
left: 20px;
width: 200px;
height: 100px;
}

It sounds like you are creating a modal dialog. You can use jQueryUI to handle this:
http://jqueryui.com/demos/dialog/#modal-confirmation

Sounds like you're looking for a modal
You can use a jQuery UI Modal

BlockUI jQuery plugin is an alternative to using jQuery UI modals. This is a neat demo that shows how you can disable a specific background element in a slightly different fashion: http://jquery.malsup.com/block/#element

To answer your question update:
You could make your gif transparent with CSS2.1 and CSS3 because there are problems with transparent gifs/pngs in some browsers:
#overlay {
background-image: url('../images/transparent.gif');
width:100%;
height:100%;
z-index:8999;
display:none;
margin-top: 0;
margin-left:0;
position:fixed;
/* for IE, the filter only works reliably on positioned elements */
filter: alpha(opacity=40); -moz-opacity: 40%; opacity: 0.4;
}

Related

css blur effect on a live background [duplicate]

This question already has answers here:
How to use CSS (and JavaScript?) to create a blurred, "frosted" background?
(10 answers)
Closed 5 years ago.
I was looking for a way to blur/glass a background to create some overlays and dialogs. I stumbled upon lots of possible solutions, but none of them fits my requirement.
You can either solve this issue by using two versions of the same image (original + blurred) and then offset the blurred version in the overlay background or you could possibly use some crazy stuff like html2canvas, create a snapshot and basically go for the first solution.
The problem is, that isn't "live" at all. If something changes in the DOM, you don't catch it, especially not if you're just using a blurred version of a single image.
Gecko to the rescue?
Firefox/Gecko introduced a pretty nice css feature called element() a long time ago. It allows you to just clone the face of any element in your live DOM. That comes in pretty handy, to solve my original problem and it looks like this:
Demo: https://codepen.io/anon/pen/prLBpQ (only works in Firefox, unfortunately).
The great thing about element() is, that it is truly live, even if you move other elements within a "target" surface, it reflects instantly on your background.
As awesome as this feature is, it's only available in Firefox for years, so my only question is, if there is any other smart way to create a similar live effect on webkit, which I could not think of at present.
// Js only for drag the articles
$(function() {
$( "article" ).draggable();
});
html {
background: url(https://2.bp.blogspot.com/-LwilPQw9Zc0/Unzm09oXDxI/AAAAAAAAHwo/30a7ZqSp3jE/s1600/blur-static+.jpg) no-repeat 50% fixed;
background-size: cover;
}
body {
width: 100%;
min-height: 100%;
background: inherit;
overflow: hidden;
}
article {
background: inherit;
position: relative;
width: 60%;
margin: 10vh auto 15vh;
border-radius: 15px;
border: 10px solid rgba(255,255,255,.15);
box-shadow: 1px 1px 4px rgba(0,0,0,.3);
z-index: 5;
font-size: 1.4rem;
cursor: move;
}
article:before {
content: '';
position: absolute;
top: 0; left:0; right:0; bottom:0;
background: inherit;
filter: blur(5px);
-webkit-filter: blur(6px);
-moz-filter: blur(6px);
-o-filter: blur(6px);
-ms-filter: blur(6px);
filter: url(#blur);filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='6');
}
<article>
<h2>Blur effect</h2>
</article>
<svg version="1.1" xmlns='http://www.w3.org/2000/svg'>
<filter id='blur'>
<feGaussianBlur stdDeviation='6' />
</filter>
</svg>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

IE10- transparent overlay using z-index

I am working on beautification of javascript alert.I need a transparent overlay which overlay the whole page other than the alert block,just like the origin javascript alert.
The html:
<html>
<body>
<div class="alert-overlay">
<div class="alert-block"></div>
</div>
</body>
</html>
The css of the overlay:
.alert-overlay {
width: 100%;
height: 100%;
position: fixed;
z-index: 1100;
left:0;
top:0;
}
The css of the alert block:
.alert-block{
position:absolute;
top:30%;
left:50%;
width: 300px;
background-color: #fff;
margin-left: -150px;
border-radius: 5px;
z-index:1200;
}
It works in IE11,chrome and firefox,but failed in IE10-.
The overlay seems overlay nothing in IE10-,all the elements on the page are active.Strangely,if I add a background-color:black,it will overlay everything but the alert-block,and make the page inactive like the origin javascript alert except the additional background,which is not what I want.
So how can I make the transparent overlay work on IE10-?Is that a z-index bug?
IE10 has some issues. Try giving a background with filter. Here is how you can do it-
background:white; filter:alpha(opacity=1);
Some helpful links :
z-index problem in IE with transparent div
IE z-index trouble on element with transparent background
Hope it helps.
IE10 and less allow actions through elements when it's not having any backgorund or content. You must add a background to your overlay. Use a transparent one if you don't want it to be visible:
background-color: rgba(0,0,0,0);

Blur changing elements behind div

First of all I want to make clear that I already have searched for some solutions. And I also have seen some 'blur issues' here on stackoverflow. But mine is just little different.
I want to blur the part of a slideshow that falls behind a transparent div element. On my testserver I have a preview to make it understandable you can check it here.
The things I have already tried:
- blurjs.com
- CSS only blur wich you can check here
- Google
These two basicly do the same, both the solutions don't support changing backgrounds. Maybe you guys know a solution.
I hope you can help me. Thanks.
The code I have till now:
<div id="blur-overlay"></div>
<div id="slideshow">
<div class="slide active"><img src="http://www.zastavki.com/pictures/originals/2012/Space_Earth_from_space_035859_.jpg" alt="Slideshow Image 1" /></div>
<div class="slide"><img src="http://www.zastavki.com/pictures/originals/2012/Space_Full_Moon_from_the_Earth_035858_.jpg" alt="Slideshow Image 2" /></div>
<div class="slide"><img src="http://i.space.com/images/i/000/005/402/original/hubble-space-bubble-photo-2-100622-02.jpg?1292270748" alt="Slideshow Image 3" /></div>
</div>
and the CSS:
#blur-overlay {
width: 250px;
height: 250px;
border-radius: 100%;
background: rgba(255, 255, 255, 0.5);
position: absolute;
top: 105px;
left: 50%;
margin-left: -125px;
z-index: 100;
}
#slideshow {
position:relative;
height:300px;
width:1000px;
float: left;
overflow: hidden;
}
#slideshow .slide {
position:absolute;
top:0;
left:0;
z-index:8;
opacity:0.0;
}
#slideshow div {
display: none;
}
#slideshow div img {
width: 100%;
float: left;
position: relative;
}
#slideshow div.active {
display: block;
z-index:10;
opacity:1.0;
}
#slideshow div.last-active {
z-index:9;
}
(as far as I'm aware) There is no easy way to make that happen. This is because CSS blurs only apply to specific elements. So you could blur your transparent circle, but it will not affect whatever is behind it.
The only possible solution I can think of would be to have TWO slideshows running at once. The one you already have, and then a second one on top. The second one would have CSS blur applied. Then on the blurred slideshow, you could use CSS to make it a circle with overflow hidden.
EDIT: I misunderstood what was trying to be done. The poster wishes to blur the background behind a div and not the div itself. Only way to do that is to have a part of the image blurred, which is actually also covered in the article. Also refer to the other answer.
Original:
I think this is a symptom of not reading through the articles fully. Here's a code example right from the article(CSS Gaussian blur behind a translucent box):
#search {
filter: blur(10px); /* Doesn't work anywhere yet */
-webkit-filter: blur(10px);
filter: url('blur.svg#blur'); /* for Firefox - http://jordanhollinger.com/media/blur.svg */
}
On looking at your site, I saw this:
#blur-overlay {
filter: blur(15px);
}
The article clearly states that this css property doesn't work anywhere. It goes on with code examples of what works(this is what I gave you).
For firefox compatibility, it links to an svg document's blur definition.
To do this specific thing, create an svg file(you can embed this into your document or host it somewhere else):
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="svg_blur" x="0" y="0">
<feGaussianBlur in="SourceGraphic" stdDeviation="15" />
</filter>
</defs>
</svg>
Add the corresponding url() to your css file like this:
#blur-overlay {
filter: blur(10px);
-webkit-filter: blur(10px);
/* If you're using an SVG in the document */
filter: url('#svg_blur');
/* If you're using an SVG hosted on your web server, say at /static/blur.svg */
filter: url('/static/blur.svg#svg_blur');
}

Center an image inside div using formula

I am using a formula method to center the image inside the div.
Here is the link: http://fiddle.jshell.net/bPM73/10/
I don't know what is wrong in the formula, that image is not getting centered.
I mean I want both vertically and horizontally
Please help.
you can made it only with css3 box-align property… working with all browsers (with prefix hack)
http://fiddle.jshell.net/bPM73/28/
#i4 {
display: block;
width:300px;
height:160px;
top:0px;
left: 0px;
right: 0px;
bottom: 0px;
position:absolute;
margin: auto;
}
Here is a trick. You can copy it into your fiddle and see it will works.
I have edited the js and added position:relative to your wrapper div. check this out http://fiddle.jshell.net/bPM73/24/

How can I make a div horizontally slide in?

I currently have a div appearing on hover, but it just pops up rather than sliding in:
#home-heroImage{
padding: 0px;
margin: 0px auto;
width:980px;
height: 525px;
position: relative;
z-index: 1;
background-color: #fcba2e;
}
#home-hero-pop{
background-color: #ffffff;
opacity:0.8;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
filter: alpha(opacity=80);
font: 16px Helvetica,Arial,sans-serif;
font-weight: bold;
color: #6d6e70;
text-align: left;
padding: 10px;
position: absolute;
right: 0px;
top: 0px;
height: 505px;
width: 460px;
z-index: 2;
}
Fiddle.
After looking through the posts on SO, I found this example, which would work if I could get it to slide in from the right instead of the bottom. I don't know much about JavaScript or jQuery so the modifications I've tried to make to this code are not producing the desired effect:
$(document).ready(function(){
$('.up-down').mouseover(function(){
$('.default').stop().animate({
height: 0
}, 200);
}).mouseout(function(){
$('.default').stop().animate({
height: 200
}, 200)
})
});
Fiddle.
I've tried reading several JavaScript articles online but they're over my head right now.
Based on the example you give, here's it sliding in from the right.. is this what you are after? http://jsfiddle.net/jPneT/208/
EDIT 2017
Too much jQuery
You're right, here's a CSS alternative
.left-right {
overflow:hidden;
height:200px;
width:200px;
position:relative;
background-color:#333;
}
.slider {
width:200px;
height:200px;
position:absolute;
top:0;
right:-200px;
background-color:#000;
color:#fff;
transition:0.4s ease;
}
.left-right:hover .slider {
right:0;
}
<div class="left-right">
<div class="slider">Welcome !</div>
</div>
My answer uses no JavaScript. CSS can handle this automatically for you.
Here's a link to a fork of your code as a working example:
http://jsfiddle.net/g105b/Adk8r/11/
There is only a little change from your example. Rather than hiding the element and showing it with display property, the element is placed off-screen using right: -480px (where 480 is the cumulative width), and moving it to right: 0 when the mouse hovers.
Using CSS transitions provides the animation, and support is very good now: http://www.caniuse.com/#search=transition
This technique allows all browsers back to IE6 view and use your website, but users with older browsers will not have an enhanced experience. Unless you require the animation - as in, it is a feature for it to animate - I would suggest using CSS transitions to futureproof your website and use web standards.
Users of deprecated browsers deserve a deprecated experience.
Fiddle: http://jsfiddle.net/BramVanroy/Adk8r/10/
As said: please learn to write logical and correct HTML. Your markup is invalid and unlogical. You should perfect your HTML and CSS and then study JavaScript and jQuery rather than trying to get a hang of everything at once. This code is a pain to the eye.
Here's what's wrong:
Try to avoid large chunks of inline style and JavaScript.
You use a span where one would use a heading-tag (<h1>Welcome</h1>) and style it via CSS.
You use line breaks <br /> where one would use paragraphs:
<p>This div appears on hover but I would like to slide in from the right instead of just appearing.</p>
There's no structure in your code. This is not necessary to create a working website, but it's good practice to give child elements an indent of two or four spaces. This way, it's very clear for yourself which element is which child or parent. The same is true for your CSS rules: it's better to put your selector first and then the rules (indented) like so:
h1 {
font-weight: bold;
font-size: 160%;
}
You have a closing </a> tag but there's no opening <a>.
There is a very simple way to do it using css3.
instead of going through the hassle of javascript
try something like in the CSS:
div.move {
height: 200px;
width: 200px;
background:#0000FF;
color:#FFFFFF;
padding:10px;
}
/*on mouse hover*/
div.move:hover {
/*General*/
transform:translate(200px,100px);
/*Firefox*/
-moz-transform:translate(200px,200px);
/*Microsoft Internet Explorer*/
-ms-transform:translate(200px,100px);
/*Chrome, Safari*/
-webkit-transform:translate(200px,100px);
/*Opera*/
-o-transform:translate(200px,100px);
}
in the HTML:
<div class="move">Anything is here moves!</div>
Also the translate works on an x/y axis.
This is very simple. All you need is HTML, CSS and jQuery.
Make a solid div.
Make the parent div to hide overflow (overflow:hidden) in CSS.
Assign a margin-left of 100% (or some length) that the required div hides away because of margin.
Do a jquery animate() function to bring down margin-left to 0 or 0%.
You can also set the speed of animation by giving time in ms (milliseconds) or some expression like slow or fast

Categories

Resources