Laptop lid-open effect - javascript

I love the way the MacBook opens on the WhitePage (http://whitepagehq.com) homepage. I'd like to create a similar effect.
Is this created using CSS Animation, JQuery, or both? I can't seem to figure out from the Inspector. Have you seen a similar animation somewhere else?
How can I make something like this for my website?

There are two images:
<img src="lib/img/laptop-closed.png" class="lid-closed"/>
<img src="lib/img/laptop-open.png?1" class="lid-open"/>
The animation simply involves changing the laptop-open.png image's height on document ready.
This is done using jQuery (within the main page from line 126):
setTimeout(function () {
$('.lid-closed').animate({
top:10,
height:9,
width:840
}, {
easing:'linear',
duration:500
});
$('.lid-open').animate({
height:207
}, {
easing:'easeOutQuad',
duration:1000
});
}, 1000);

They are using jquery to animate the height of the open laptop image:
setTimeout(function(){
$('.lid-closed').animate({
top: 10,
height: 9,
width: 840
},
{
easing: 'linear',
duration: 500
});$('.lid-open').animate({
height: 207
},
{
easing: 'easeOutQuad',
duration: 1000
});
},
1000);

This code is done by jQuery.animate() method, you can find it in their inline js script. (View Source -> line 126). Basically they vary the height of the 'open' image at the same time as the 'closed' image. Open image expands and the closed part of the lid moves up.

Related

DIV moving up and down using javascript

Good day,
I'm building a website where I would like to have a div moving down and back up on a click(clicking on another div area).
It regards the header of a page with an account image inside (the header contains from left to right: logo, horizontal menu, shopping cart and account symbol)
when I click the account symbol I want the header to slide down (60 pixels) and I want another div (with account related links in it) to show up above the header that just slid down.
I've achieved something but I'm really not happy with it:
<script>
jQuery(document).ready(function($){
$(".account").click(function);
$("#accountbar").slideToggle( "slow");
$("#topheader").toggleClass("topheader topheaderdown");
$("#contentarea").toggleClass("content contentdown");
});
});
</script>
1) So what this does it loads the new account bar (height 60px) and slides this one down.
2) It displays the topheader down another 60px (css style rule top: 60px)
3) It also displays the rest of the content (the main content) down 120 pixels lower than normal when both the account bar and topheader are being displayed (by default this value is 60px, so only for the topheader)
I want things to "smoothly" slide down and back up when clicking on the account image. I got this far (for the smoothly moving down the topheader part):
<script>
jQuery(document).ready(function($){
$("#account").on('click',function(){
$("#accountinner").toggle(function() {
$("#topheaderid").animate({ top: '-=60px' }, 500);
},function() {
$("#topheaderid").animate({ top: '+=60px' }, 500);
})
});
});
</script>
PROBLEM 1: the above is only moving the topheader down further and further every time I click on it (not going back up 60px again as specified)...
PROBLEM 2: The above is also somehow sliding my account image to the right (out of screen)
And I would like to implement the other rules in this too, so that on a click the topheader just moves down smoothly with 60px, up the top appears the account navigation in a new div (accountbar) AND the content (class content) moves down another 60px. As said before using "slidetoggle" and "toggleclass" works but I much rather have the "animate" function do the job as this looks awesome.
I have implemented these rules from the first script but it does not happen "smoothly" obviously and the topheader just keeps on going down...
I hope this is enough info and someone can help :)
When this works I want to extend this with a search button as well that appears below the topheader on click.
https://jsfiddle.net/d14tcb9n
Thanks.
You can trigger the animations like:
jQuery(document).ready(function($){
$("#account").on('click',function(){
if($(this).hasClass('open')) {
$("#topheaderid").animate({ top: '0' }, { duration: 500, queue: false });
$("#accountbar").animate({ height: '0' }, { duration: 500, queue: false });
$('#contentid').animate({ marginTop: '60px' }, { duration: 500, queue: false });
$(this).removeClass('open');
} else {
$("#topheaderid").animate({ top: '60px' }, { duration: 500, queue: false });
$("#accountbar").animate({ height: '60px' }, { duration: 500, queue: false });
$('#contentid').animate({ marginTop: '120px' }, { duration: 500, queue: false });
$(this).addClass('open');
}
});
});
remove the display none from the hidden div and change the height to 0
demo:https://jsfiddle.net/o1cvho6m/

Make .delay() and .animate() function re-run everytime a classes div opens

So, I'm sure there is a simple answer to this, but after 2 days of research I cannot find a solution.
The Story:
I have a dynamic page. When you get to one section and click on one of the 6 options it pulls up some info (name, place, etc.). I have a jQuery function that makes that info hide about half way after a few seconds. When you hover over that section with the mouse it also will animate up and back down as the mouse leaves it.
The Problem:
How do I make the whole function run again if another of those 6 option is clicked? Each time an option is selected the class with that info comes up, but after this function runs once (the delay part and animate down part) it just stays minimized unless you hover over it. I want it to appear every time and then run through the function. I have tried a number of things, and I'm sure there is a simple solution, just not sure what it is.
Here is a link to my codepen with a sample: http://codepen.io/jsegarra/pen/GxByr
I have also tried to wrap that all in a click function, for clicking on one of those 6 options and thought that would do the trick, but still the same thing:
$(document).ready(function () {
$('.title').click(function () {
$('.bottomTab').delay(5000).animate({
height: '50px' // to 50px
}, 'slow');
$(".bottomTab").hover(
//on mouseover
function () {
$(this).stop().animate({
height: '+=100' //adds 50px
}, 'slow');
},
//on mouseout
function () {
$(this).stop().animate({
height: '50px' //back to 50px
}, 'slow');
});
});
});
Just reset the div css before re-running the function
$(document).ready(function () {
$('.title').click(function () {
$('.bottomTab').css('height', '100px').delay(500).animate({
height: '50px' // to 50px
}, 'slow');
$(".bottomTab").hover(
//on mouseover
function () {
$(this).stop().animate({
height: '+=100' //adds 50px
}, 'slow');
},
//on mouseout
function () {
$(this).stop().animate({
height: '50px' //back to 50px
}, 'slow');
});
});
});
Here is the html I used with that javascript
<div class="title">title</div>
<div class="bottomTab">This is going to move from just being about 50 pixels high to about 100 pixels high after i add in some mouseenter and mouse out events</div>
I used the same CSS of your code pen, and the result was a full reclickable option
I don't see the problem. Your code seems to works fine. You've just typed an error while transfering to CodePen. Replace $('this').hover( with $('.bottomTab').hover(.

Passing easing behaviors between elements, jQueryUI

I have an object accordionOptions which mediates the behavior of an accordion object
on my page. It looks like:
var accordionOptions = {
icons: {
header: 'ui-icon-circle-arrows-e',
activeHeader: 'ui-icon-notice'
},
animate: {
easing: 'easeOutBounce',
duration: 1000
}
}
I'm using that object to determine the behavior of my accordion like so:
$('#accordion1').accordion({
icons: accordionOptions.icons,
animate: accordionOptions.animate
});
I have an anchor tag on my page that when clicked I intend for it to have the same animation as the accordion when a new panel is clicked:
$('#btnChange').click(function () {
$('#test').animate({
easing: accordionOptions.animate.easing
});
});
You can see in the fiddle here this doesn't work. I've tried several things, all were non-successes. How can I attach my desired behavior to the test div using my accordionOptions argument?
Using easing for .animate is slightly different than for .accordion -- you need to pass the duration and easing separately from what should be animated. You should set a height or whatever property it should animate.
$('#test').animate({ height: 100 }, accordionOptions.animate.duration, accordionOptions.animate.easing);
Or shorter syntax similar to how you were originally doing it:
$('#test').animate({ height: 100 }, accordionOptions.animate);
Updated fiddle: http://jsfiddle.net/C6Eax/1/

Why isn't this jquery animation rotating like it's supposed to?

This .js works perfectly in the fiddle
function animationLoop() {
$("#ToBeAnimated").css({
top: ($("#paperTrail").offset().top - parseInt($("#ToBeAnimated").height()) / 2),
left: ($("#paperTrail").offset().left - parseInt($("#ToBeAnimated").width()) / 2)
}).rotate(270);
$("#ToBeAnimated").animate({
top: $("#paperTrail").offset().top + $("#paperTrail").height() - $("#ToBeAnimated").height() / 2
}, 1000, function() {
$(this).animate({
rotate: "180deg"
}, function() {
$("#ToBeAnimated").animate({
left: $("#paperTrail").offset().left + $("#paperTrail").width() - $("#ToBeAnimated").width() / 2
}, 1000, function() {
$(this).animate({
rotate: "90deg"
}, function() {
$("#ToBeAnimated").animate({
top: $("#paperTrail").offset().top - $("#ToBeAnimated").height() / 2
}, 1000, function() {
$(this).animate({
rotate: "0deg"
}, function() {
$("#ToBeAnimated").animate({
left: $("#ToBeAnimated").width() / 2
}, 1000, function() {
setTimeout(animationLoop, 1000);
});
});
});
});
});
});
});
}
animationLoop();​
But on the actual site the scissor rotation isn't working or is somehow broken... I have inspected it... guessed and checked... researched possible conflicts...But Im stuck! Maybe I am missing something obvious?
Thanks a million for helping!... To see the animation on the live site just click the "Clip It!!!" button at the bottom of the 1st coupon!
extreme coupon network
UPDATE: It's something to do with having multiple instances of the animation on the page... When I look at a page with one result it works for me... HOWEVER... I am still unable to make it work with many items on the page (which is what I am really after).... Ideally... Whichever coupon you click on will have the animation appear on it... Currently the animation only works on the 1st coupon... and very shakey
Thanks again!
The fiddle you are testing with is using jQuery version 1.8.2. On your webpage, however, you are using version 1.7.2. If you change your jQuery version in the fiddle to 1.7.2, you get exactly the same buggy behavior (jerky animation in FF, no rotation in IE or Chrome) as on your page.
Solution: Update the version of jQuery you're using in your project!

jQuery animation perform poorly all over. How can I make it smoother?

I tried to emulate the effect in the slider on this site: http://metalabdesign.com/
Here's the animation code:
$('.tagLink').click(function () {
$('html').css('overflow', 'hidden');
$('#tagBoxOverlay').show().stop(1).fadeTo(200, .9)
$('#tagBox').show().stop(1).animate({
marginTop: '-37.5%',
marginLeft: '-37.5%',
height: '75%',
width: '75%',
opacity: 1
}, {
duration: 200,
specialEasing: {
opacity: 'linear',
width: 'linear',
height: 'linear',
marginLeft: 'linear',
marginTop: 'linear'
},
complete: function () {
$(tagBoxContents).fadeTo(200, 1);
$('#tagBoxPopularWrapper').height($('#tagBox').height() - $('#tagBoxDescription').height() - 1);
$(window).resize(function () {
$('#tagBoxPopularWrapper').height($('#tagBox').height() - $('#tagBoxDescription').height() - 1)
});
}
});
tagBoxOverflow and tagBox start out 100% width & height. Overlay fades in, and the box both fades in and shrinks.
Here's a site where you can see it live: http://hashtraffic.com/
Hit "begin" then click "hipsters" and it will do the animation.
Why is it so slow? Here's a link to the RAW JS:
http://hashtraffic.com/js/HashTraffic.js
I'm so lost here. I understand I'm asking a lot of the browser, but metalabs does it just fine! Would it be smoother if I used CSS animations with js fallback?
Definately smoother to use css3 transitions (but IE does not reward us for this).
But I think a major problem is your margins.
I would make it position: absolute. and animate top right bottom and left.
With what your doing,the browser is forced to reflow the entire page, but if you make the position absolute, resizing does not effect the containing element or any of its parents.

Categories

Resources