I put together a short script for a fellow classmate and thought I would show a nice backgound fade to make it look nicer. I can achieve the color change but it will not transition smoothly from one state to the next. I thought this would work but perhaps I am wrong or missed something.
Everything else in the script works so go ahead and use if you wish. All it does is cause a screen halt so a error or message can be displayed before doing anything else.
the template:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Message Expansion Demonstration</title>
<style>
body {
margin:0 auto;
padding:0 0;
height:100%;
width:100%;
text-align:center; }
#haltPage {
display:none;
position:absolute;
height:100%;
width:100%;
top:0px;
background-color:rgba(0, 0, 0, 0.0);
transition: background-color 1s linear .1;
-webkit-transition: background-color 1s linear .1;
-o-transition: background-color 1s linear .1;
z-index=9999;
}
.wrong {
position:relative;
padding:auto auto;
margin:auto auto;
height:250px;
width:400px;
background-color:#666;
border-bottom-left-radius:0.5em 0.5em;
border-bottom-right-radius:0.5em 0.5em;
border-top-left-radius:0.5em 0.5em;
border-top-right-radius:0.5em 0.5em;
box-shadow:5px 10px 25px #000; }
.wrong p {
padding:10px; }
</style>
<script>
function wrong ( classID )
{
var on = 'block';
var visable = 'rgba(0, 0, 0, 0.4)';
clearClass ( );
document.getElementById('haltPage').style.display = on;
document.getElementById('haltPage').style.backgroundColor = visable;
document.getElementById(classID).style.display = on;
}
function clearClass ( )
{
var off = 'none';
document.getElementById('haltPage').style.display = off;
document.getElementById('wrong1').style.display = off;
document.getElementById('wrong2').style.display = off;
document.getElementById('wrong3').style.display = off;
}
</script>
</head>
<body>
Wrong Answer One<br><br>
Wrong Answer Two<br><br>
Wrong Answer Three<br><br>
<!-- This is not seen untill called -->
<div id="haltPage">
<br><br><br>
<div id="wrong1" class="wrong">
<h1>Wrong!</h1>
<p>You are wrong!<br>Close</p>
</div>
<div id="wrong2" class="wrong">
<h1>Wrong!</h1>
<p>You are wronger! < Not a word<br>Close</p>
</div>
<div id="wrong3" class="wrong">
<h1>Wrong!</h1>
<p>You are wrongest! < duh<br>Close</p>
</div>
</div>
</body>
</html>
Try by adding an "s" behind the values for time in your CSS definition for "#haltPage":
transition: background-color 1s linear .1s;
-webkit-transition: background-color 1s linear .1s;
-o-transition: background-color 1s linear .1s;
Related
I have a code for an image that if you tap on it zooms out and if you tap on any where out side the box of the image it zooms back. is there I can control the zooming with a button such that one button zooms incrementally and the other zooms in decrementally. this is my attempt
<!DOCTYPE html>
<html >
<head>
<style type="text/css">
.zoomin img { height: 200px; width: 200px;
-webkit-transition: all 2s ease;
-moz-transition: all 2s ease;
-ms-transition: all 2s ease;
transition: all 2s ease; }
.zoomin img:hover { width: 300px; height: 300px; }
</style>
</head>
<body>
<div class="zoomin">
<img src="download.jpg" title="All you need to know about CSS Transitions " />
</div>
</body>
</html>
<button>plus</button>
<button>minus</button>
what better way could this be achieved
Simply change dimensions of image using .style.[width/height], css will do the rest:
function resize(direction) {
var delta = 100 * direction;
var element = document.getElementById('img');
var positionInfo = element.getBoundingClientRect();
element.style.width = positionInfo.width+delta+'px';
element.style.height = positionInfo.height+delta+'px';
}
<!DOCTYPE html>
<html >
<head>
<style type="text/css">
.zoomin img { height: 200px; width: 200px;
-webkit-transition: all 2s ease;
-moz-transition: all 2s ease;
-ms-transition: all 2s ease;
transition: all 2s ease; }
.zoomin img:hover { width: 300px; height: 300px; }
</style>
</head>
<body>
<div class="zoomin">
<img src="download.jpg" id="img" title="All you need to know about CSS Transitions " />
</div>
</body>
</html>
<button onClick="resize(1)">plus</button>
<button onClick="resize(-1)">minus</button>
This works, I've given each button a class, one plus and one minus, and have addClass and removeClass. An even easier way would be to have one button and use toggleClass to add and remove the class you already have for zoomin.
$('button.zoomPlus').click(function(){
$('.zoomin img').addClass('zoomer');
});
$('button.zoomMinus').click(function(){
$('.zoomin img').removeClass('zoomer');
});
.zoomin img { height: 200px; width: 200px;
-webkit-transition: all 2s ease;
-moz-transition: all 2s ease;
-ms-transition: all 2s ease;
transition: all 2s ease; }
.zoomin img:hover,
img.zoomer{ width: 300px; height: 300px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!DOCTYPE html>
<html >
<head>
</head>
<body>
<div class="zoomin">
<img src="http://placehold.it/300x300" title="All you need to know about CSS Transitions " />
</div>
</body>
</html>
<button class="zoomPlus">plus</button>
<button class="zoomMinus">minus</button>
when i am trying to move image to the center that time the browser can showing the error can not read property width of null . I am trying to divide the width of the screen by 2 i can t understan why that error is showing .
var mobile = document.getElementById("mobile");
var monitor = document.getElementById("monitor");
var tab = document.getElementById("tab");
var header = document.getElementById("header");
var position = (screen.width - monitor.width)/2;
monitor.style.left = position+"px;";
function initScroll(){
if(window.pageYOffset >500){
mobile.style.left = "300px";
tab.style.right = "250px";
header.style.height = "60px";
header.style.fontSize = "25px";
}else{
header.style.height = "60px";
header.style.fontSize = "25px";
mobile.style.left = "0px";
tab.style.right = "0px";
}
}
window.addEventListener("scroll",initScroll);
*{padding: 0;margin: 0;font-family:arial;}
#header{height:100px;background-color: #354458;font-size: 40px;color:#fff; text-align:center;line-height:2.5;
position:fixed; width:100%;z-index:20;
-moz-transition: 2s height, 2s font-size;
-o-transition: 2s height, 2s font-size;
-webkit-transition: 2s height, 2s font-size;
transition: 2s height, 2s font-size;
}
#banner{background: #3a9ad9;height:400px;position:fixed;width:100%;
top:100px;font-size:50px; text-align: center; color
:#fff;z-index:10;
}
#banner > * {
margin-top:30px;
}
#content{
top:500px;
position:relative;
height:1000px;
padding-top:200px;
background-color: #fff;
z-index:15;
}
#mobile{
position: absolute;
left: 0;
z-index: 15;
top: 470px;
-moz-transition: 2s left;
-o-transition: 2s left;
-webkit-transition: 2s left;
transition: 2s left;
}
#monitar{position: relative;}
#tab{
position: absolute;
right: 0;
z-index: 15;
top: 385px;
-moz-transition: 2s right;
-o-transition: 2s right;
-webkit-transition: 2s right;
transition: 2s right;
}
<html>
<head>
<title>Java script Scroller</title>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="./css/style.css"/>
<script src="./js/custom.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">Header</div>
<div id="banner">
<h1>My Animation</h1>
<h2>First collapsable header</h2>
<h3>Apurva Kinkar</h3>
</div>
<div id="content">
<img id="mobile" src="./img/1.jpg" />
<img id="monitar" src="./img/2.png" />
<img id="tab" src="./img/3.jpg" />
</div>
</div>
</body>
</html>
You have a typo error with your <img> declaration, It has to be monitor not monitar
<img id="monitar" src="./img/2.png" />
Change this as,
<img id="monitor" src="./img/2.png" />
Hope this helps!
Firstly, your image id is wrongly spelled.
Change this :-
<img id="monitar" src="./img/2.png" />
to
<img id="monitor" src="./img/2.png" />
After changing this, you will still get the same error. This is because, when your js code runs, the img element is still not added to the DOM.
For that, make the javascript code run on document.ready function ( when the img with id "monitor" is present in the DOM ).
Here is the working example which uses jQuery's document.ready() function.
You can also use this example if your dont want to use jQuery.
I'm having a slight problem with css transition. On my website, I have a div, and in that div is a h1.
Here's the css code.
#inner1 {
background-image: url("rsz_astromenu1.jpg");
height: 333px;
width: 500px;
display: inline-block;
opacity: 0.5;
font-size: 10px;
}
#inner1:hover {
font-size: 50px;
transition: font-size 1s linear;
opacity: 1;
transition: opacity 1s linear;
}
I want to animate the opacity (from 0.5 to 1) and font-size (from 10px to 50px).
However, when I hover my mouse over that div, the opacity is nicely transitioned, but the text just changes the size instantly. So the hover seems to work and change the font-size, why is transition omitted?
If I make it #inner1 h1:hover, the transition works properly but only when I hover over the text. And I want the font-size transition when I hover over that div.
I tried to work around the problem and write a JS script for enlarging the text.
Here's what I came up with. I'll paste all the HTML content as well since there's not much of it.
However, this is not really smooth, I've gone as far as to incrementing only 0.09px every millisecond, but it still looks bumpy and also sends hundreds of unnecessary commands to the browser, right?
How can I solve that problem? Either with CSS or JS?
Thanks in advance ;).
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Gallery</title>
<link rel="stylesheet" type="text/css" href="mainStyle.css">
</head>
<body>
<div id="outer">
<div id="middle">
<div id="inner1" class="hover-menu">
<h1 id="astro-h1" class="hover-menu">Astrofotografia</h1>
</div>
<div id="inner2"></div>
</div>
</div>
<script>
var JSinner1 = document.getElementById("inner1");
var JSastroh1 = document.getElementById("astro-h1")
JSastroh1.style.fontSize = "16px";
var textBigger = function() {
var newSize = parseFloat(JSastroh1.style.fontSize) + 0.009 + "px";
window.setInterval(textBigger, 1)
if (parseFloat(newSize) < 60) {
JSastroh1.style.fontSize = newSize;
console.log(newSize);
}
}
JSinner1.addEventListener("mouseover", textBigger)
</script>
</body>
</html>
You're overwriting one transition with another. Try with
transition: font-size 1s linear,opacity 1s linear;
It's very simple, the problem is your :hoverselector, as you are adding two transitions properties, the last one is overwriting the previous one. In order to make this work, just add this to that rule:
transition: opacity 1s linear, font-size 1s linear;
Or you can use
transition: all 1s linear;
instead of using
transition: font-size 1s linear;
transition: opacity 1s linear;
use all
transition: all 1s linear;
or merge the two into one transition: font-size 1s linear,opacity 1s linear;
#inner1 {
background-image: url("rsz_astromenu1.jpg");
height: 333px;
width: 500px;
display: inline-block;
opacity: 0.5;
font-size: 10px;
}
#inner1:hover {
font-size: 50px;
opacity: 1;
transition: all 1s linear;
}
<div id="inner1">
<h1> Some text </h1>
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
#inner1 {
background-image: url("rsz_astromenu1.jpg");
height: 333px;
width: 500px;
display: inline-block;
opacity: 0.5;
font-size: 10px;
transition: opacity 1s linear, font-size 1s linear;
}
#inner1:hover {
font-size: 50px;
opacity: 1;
}
</style>
</head>
<body>
<div id="outer">
<div id="middle">
<div id="inner1" class="hover-menu">
<h1 id="astro-h1" class="hover-menu">Astrofotografia</h1>
</div>
<div id="inner2"></div>
</div>
</div>
</body>
</html>
I'm trying to get a full-screen image background with a scrollable div on its center, so I wrote this code
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bio</title>
<link href="../css/layout-base.css" rel="stylesheet">
<script type="text/javascript" src="../jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(window).ready(function(){
var background = $('#background');
var scrollable = $('#scrollable-container');
var halfWhite = $('#halfWhite');
var halfBlack = $('#halfBlack');
/* calcolo dimensione finestra */
var maxWidth = $(window).width();
var maxHeight = $(window).height();
/* settaggio dimensioni immagine sfondo */
background.css("height",maxHeight);
background.css("width",maxWidth);
scrollable.css("height",maxHeight);
/* settaggio dimensioni riempimento sfondo */
halfWhite.css("height",maxHeight);
halfWhite.css("width",maxWidth/2);
halfBlack.css("height",maxHeight);
halfBlack.css("width",maxWidth/2);
});
$(window).resize(function(){
var background = $('#background');
var scrollable = $('#scrollable-container');
var halfWhite = $('#halfWhite');
var halfBlack = $('#halfBlack');
/* calcolo dimensione finestra */
var maxWidth = $(window).width();
var maxHeight = $(window).height();
/* settaggio dimensioni immagine sfondo */
background.css("height",maxHeight);
background.css("width",maxWidth);
scrollable.css("height",maxHeight);
/* settaggio dimensioni riempimento sfondo */
halfWhite.css("height",maxHeight);
halfWhite.css("width",maxWidth/2);
halfBlack.css("height",maxHeight);
halfBlack.css("width",maxWidth/2);
});
</script>
</head>
<body>
<div id="background">
<div id="halfWhite"></div>
<div id="halfBlack"></div>
<div id="scrollable-container">
<div class="content">
<div id="text"></div>
<img src="../media/index/tasto1.png"/>
<img src="../media/index/tasto2.png"/>
<img src="../media/index/tasto3.png"/>
<img src="../media/index/tasto4.png"/>
</div><!--div content -->
</div>
</div><!-- div background -->
</body>
</html>
With the relative css:
body{
overflow:hidden;
margin:0!important;
}
#background{
background-image:url(../media/index/back.png);
background-size:contain;
background-position:center;
background-repeat:no-repeat;
}
#halfWhite{
position:relative;
background-color: white;
z-index: -10;
float: left;
}
#halfBlack{
position:relative;
background-color: black;
z-index: -10;
float: right;
}
#scrollable-container{margin-left: 15%;margin-right: 15%;background- color:rgba(0,0,0,0.00);}
.content{
height:98%;
position: relative;
top:1%;
padding-left: 15%;
padding-right: 15%;
box-shadow: -10px 2px 15px #dedede,10px -2px 15px #dedede;
-moz-box-shadow:-10px 2px 15px #dedede,10px -2px 15px #dedede;
-webkit-box-shadow:-10px 2px 15px #dedede,10px -2px 15px #dedede;
background-color:rgba(255,255,255,0.8);
}
#text{position:absolute;top:10%;width:100%;height:100000px;width:70%}
.menu{
width:15%;
-webkit-transition: all 0.4s linear;
-moz-transition: all 0.4s linear;
-o-transition: all 0.4s linear;
-ms-transition: all 0.4s linear;
transition: all 0.4s linear;
}
.menu:hover{
-webkit-transform: scale(0.85,0.85);
-moz-transform: scale(0.85,0.85);
-o-transform: scale(0.85,0.85);
-ms-transform: scale(0.85,0.85);
transform: scale(0.85,0.85);
}
.menu img{width:100%}
#home{position:absolute;top:0px;left:0px;}
#events{position:absolute;top:0px;right:0px;}
#gallery{position:absolute;bottom:0px;left:0px;}
#disco{position:absolute;bottom:0px;right:0px;}
I want the #text div to scroll while the rest of the page has to stay fixed (so that the background is always on the same position), but when I add overflow property to the parent divs there are strange side effects (for example, the .content div goes to the very bottom of the page).
How can I achieve this behaviour? Is this the correct way to make this kind of layout?
make this #text div style="position:fixed" and the rest parts with position:absolute.
You need to place your background first in your html and give it a property of position: fixed. Then the rest of your html needs to go on top without the fixed property.
My problem..
I have a number of images (inside hyperlinks), and I want each to darken on mouseover (i.e. apply a black mask with high opacity or something), and then go back to normal on mouseout . But I can't figure out the best way to do it.
I've tried..
Jquery color animate and some javascript references.
Setting the opacity of the image with javascript.
I don't want..
Image start at 80% opacity then go to 100% on mouseover (that's easy).
To swap between 2 images (one light & one dark), forgot the mention this sorry..
To reiterate..
I want in image (inslide a hyperlink) to darken on mouseover and then lose its darkness on mouseout.
Thoughts?
UPDATE :
This is my progress from suggestions. Looks fine in IE8, but not in FF3
<html>
<body>
<a href="http://www.google.com" style="background-color:black; opacity:1;filter:alpha(opacity=100)">
<img src="http://www.google.co.uk/intl/en_uk/images/logo.gif" width="200"
style="opacity:1;filter:alpha(opacity=100)" onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100"
onmouseover="this.style.opacity=0.6;this.filters.alpha.opacity=60" />
</a>
</body>
</html>
Thoughts?
-- Lee
ANSWER
I'm going with this (seems to work in IE8 & FF)
<html>
<head>
<style type="text/css">
.outerLink
{
background-color:black;
display:block;
opacity:1;
filter:alpha(opacity=100);
width:200px;
}
img.darkableImage
{
opacity:1;
filter:alpha(opacity=100);
}
</style>
</head>
<body>
<a href="http://www.google.com" class="outerLink">
<img src="http://www.google.co.uk/intl/en_uk/images/logo.gif" width="200"
class="darkableImage" onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100"
onmouseover="this.style.opacity=0.6;this.filters.alpha.opacity=60" />
</a>
</body>
</html>
Or, similar to erikkallen's idea, make the background of the A tag black, and make the image semitransparent on mouseover. That way you won't have to create additional divs.
CSS Only Fiddle (will only work in modern browsers)
JavaScript based Fiddle (will [probably] work in all common browsers)
Source for the CSS-based solution:
a.darken {
display: inline-block;
background: black;
padding: 0;
}
a.darken img {
display: block;
-webkit-transition: all 0.5s linear;
-moz-transition: all 0.5s linear;
-ms-transition: all 0.5s linear;
-o-transition: all 0.5s linear;
transition: all 0.5s linear;
}
a.darken:hover img {
opacity: 0.7;
}
And the image:
<a href="http://google.com" class="darken">
<img src="http://www.prelovac.com/vladimir/wp-content/uploads/2008/03/example.jpg" width="200">
</a>
Make the image 100% bright so it is clear.
And then on Img hover reduce it to whatever brightness you want.
img {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
img:hover {
-webkit-filter: brightness(70%);
filter: brightness(70%);
}
<img src="http://dummyimage.com/300x150/ebebeb/000.jpg">
That will do it,
Hope that helps
I realise this is a little late but you could add the following to your code. This won't work for transparent pngs though, you'd need a cropping mask for that. Which I'm now going to see about.
outerLink {
overflow: hidden;
position: relative;
}
outerLink:hover:after {
background: #000;
content: "";
display: block;
height: 100%;
left: 0;
opacity: 0.5;
position: absolute;
top: 0;
width: 100%;
}
How about this...
<style type="text/css">
div.frame { background-color: #000; }
img.pic:hover {
opacity: .6;
filter:alpha(opacity=60);
}
</style>
<div class="frame">
<img class="pic" src="path/to/image" />
</div>
Put a black, semitransparent, div on top of it.
Create black png with lets say 50% transparency. Overlay this on mouseover.