How to take a div that is off screen and translate it to the middle of the screen using translateX()
Tags: jquery,html,css,css3
Problem :
Let me explain a little more in depth. I'm looking to have a div off screen. When a user clicks on a button I want the div to transition onto the screen.
<a href="#" id="button">Click Me</a>
<div style="position:absolute;left:-100%;width:80%;height:80%;background:yellow; id="block" class="objecttransition"></div>
Here is the JS:
$("#button").click(function(){
$("#block".addClass("move");
}):
Here is the CSS:
.move
{
transform: translateX($$);
-webkit-transform: translateX($$); /** Safari & Chrome **/
-o-transform: translateX($$); /** Opera **/
-moz-transform: translateX($$); /** Firefox **/
}
.objecttransition
{
transition: all 0.5s linear;
-webkit-transition: all 0.5s linear; /** Chrome & Safari **/
-moz-transition: all 0.5s linear; /** Firefox **/
-o-transition: all 0.5s linear; /** Opera **/
}
My question now is by how much do I move the block to the right to make sure that the block is always in the middle of the screen regardless of the screen size??
Solution :
This actually can be done without any Javascript, anyway here's a working example using jQuery.
<div>Hello!</div>
div {
opacity: 0;
position: absolute;
top: 50%;
left: 100%;
width: 5rem;
line-height: 5rem;
text-align: center;
background: red;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50 -50%);
transform: translate(-50%, -50%);
-webkit-transition: 1200ms;
-moz-transition: 1200ms;
transition: 1200ms; }
div.foo {
opacity: 1;
left: 50%;
}
$( document ).on('click', function() {
$( 'div' ).toggleClass( 'foo' );
});
CSS Howto..
Close enough I hope: http://jsfiddle.net/UxSdU/13/ #phone-outer { border: 1px solid #FFFFFF; border-bottom-left-radius: 25px; border-bottom-right-radius: 25px; box-shadow: 0 3px 0.7px 1px #777777, 0 -7px rgba(0, 0, 0, 0.4) inset; height: 500px;...
You have three ways to do it: 1- In the following snippet, I have used a css circle inside an image div on the first moon. 2- Alternatively, got the...
You need a more specific selector. Change the selector on your second rule to: #main .page-header h1 Compare the specificity values for each selector: #main h1 0101 .page-header h1 0011...
CSS rules can be specific, for example: .page-wrapper .inner will apply rules to a specific subset of this css rule: .page-wrapper So you should specify the div which your WYSIWIG...
Chances are no. If you mean an image server control (either <asp:Image> or `) CSS is a client-side technology while any Asp.NET server controls are server-side. (keyword: in server controls...
You need to set the webkit transform origin. Basically, when you scale up it will originate from the center. This means the offset will be wrong. 0,0 will start in...
Add these to your css : .clearfix:after { content: "."; display: block; clear: both; visibility: hidden; line-height: 0; height: 0; } .clearfix { display: inline-block; } html[xmlns] .clearfix { display:...
Update your CSS .social class to the following: .social { position:fixed; right:50px; width:70px; height:400px; padding-left:10px; padding-top:50px; } That'll make it work. You have position fixed, but with position fixed and...
You nested the a rule inside the body rule. Move it outside.
You could change the name which would ensure that regardless of users browsers, they would get the new file. In all places you reference the CSS file, reference a variable...
You should have the a elements styled to inline-block and not the img. The img should be display: block. I think that should do it. #logo a { display: inline-block;...
see fiddle here use width : 100% div{position: absolute;top: 105px;left: 0;height: 47px;width: 100%;line-height: 47px;background-color: rgba(255,108,108,0.5);} ...
You can re-arrange and drop the positioning and get it to work like this: #main_content { background: #FFF; border:1px solid lightgray; } #main_content > p { margin-left: 440px; } #main_content...
gulp-sass doesn't take any file name parameters. Use gulp-rename to rename your files. If you have more than one .navbar.scss files you want to concatenate into one navbar.css files, feel...
You need a higher z-index for the hamb. Remember z-index works just for positioned elements, you need to change the default static position of the button. .overlay { position: fixed;...
Instead of using content on a non-pseudo element you should use background-image instead. I've updated your fiddle But it would go like this: .icon-search { background-image: url(https://cdn4.iconfinder.com/data/icons/wirecons-free-vector-icons/32/add-128.png); background-size: 100%; width:...
CSS can only go down the DOM tree, so you cannot add a class based on child elements, only parents. However you could use jQuery do this with a filter():...
You can use viewport unit vw to define the width of child div. A width of 100vw will take the entire screen width. Example - .parent { width: 300px; }...
change this in your div.col css definition: div#container { margin:40px 30px; } div.col { margin:-10px 10px; } as @BoltClock remarked, this doesn't work if you need the green border as...
Reading further in the spec, you will find 17.5.2.1 Fixed table layout With this (fast) algorithm, the horizontal layout of the table does not depend on the contents of the...
You can dynamically create the <link> element with JavaScript: var link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = 'css1.css'; document.head.appendChild(link); Or just edit the href attribute of...
Add this to your divs css -webkit-box-shadow: 0px 0px 121px -17px rgba(0,106,148,1); -moz-box-shadow: 0px 0px 121px -17px rgba(0,106,148,1); box-shadow: 0px 0px 121px -17px rgba(0,106,148,1); -webkit-box-shadow: inset 0px 0px 103px -17px...
You should work with padding on the inner container rather than with margin. Try this! HTML <div class="row info-panel"> <div class="col-md-4" id="server_1"> <div class="server-action-menu"> Server 1 </div> </div> </div> CSS...
How about that: if (spanResultsHeight > 30 || $divResults.is(':hidden')) { $spanResults.hide(); $resultsPopup.appendTo('#container-cpanel').fadeIn(400); } else { $spanResults.show(); }; jsFiddle...
if it is only for visual effect , you maybe have an option with transform:scale(3); to to zoom three times your element. DEMO To avoid scaling inside content, do a...
As the method name suggests, it can only return element, not text node. You can find the target <a> element first : a = driver.find_element_by_xpath('//*[@class="pg"]/ul/li[last()]/a') And then you can get...
Use viewport height units: vh #main_image { max-width: 100%; max-height: 60vh; } ...
set z-index: -9999; for the fill_link class. edited in jsfiddle...
Because the zoom level is controlled by the browser itself, the way it behaves on a per page basis cannot be adjusted using CSS/HTML/JS. A workaround would be to create...
<div>test that doesn't wrap</div> <style type="text/css"> div { white-space: nowrap; overflow: hidden; } </style> Note: this only works on block elements. If you need to do this to table cells...