jQuery fadeIn not actually fading in - javascript

I have a jQuery function where certain divs fade in and out, I cant paste my entire file into a jsFiddle as its too large and all image links are relative, I have the following however...
// On click hide default, Country specific
$('.default .asia').click(function(){
$('.default').fadeOut("fast");
$(".default").queue(function () {
$('.viewport-asia').fadeIn("fast");
$('.viewport-asia').dequeue();
});
});
$('.default .north-america').click(function(){
$('.default').fadeOut("fast");
$(".default").queue(function () {
$('.viewport-america').fadeIn("fast");
$('.viewport-america').dequeue();
});
});
$('.default .europe').click(function(){
$('.default').fadeOut("fast");
$(".default").queue(function () {
$('.viewport-europe').fadeIn("fast");
$('.viewport-europe').dequeue();
});
});
// Drag event
$(".america-big").draggable();
$(".europe-big").draggable();
$(".asia-big").draggable();
// Reset map
$('a.zoom-out').click(function(){
$('.hidden').fadeOut("fast");
$(".hidden").queue(function () {
$('.default').fadeIn("fast");
$('.hidden').dequeue();
});
})
});
The last function // Reset Map "a.zoom-out" should fade out the current div and fade in the .default div, its currently fading out the current div but the default div isn't fading back in?
Can anybody see where im going wrong?
HTML
<div class="map">
<!-- // Default Map -->
<div class="default">
<div class="asia"><img src="map/asia.png" alt="Asia"></div>
<div class="north-america"><img src="map/north-america.jpg" alt="America"></div>
<div class="europe"><img src="map/europe.jpg" alt="Europe"></div>
</div>
<!-- // Animated Map // North America -->
<div class="viewport-america hidden">
<div class="compass">
Top
Right
Bottom
Left
</div>
Zoom Out
<div class="instructions"><img src="map/instructions.png" alt="Instructions"></div>
<div class="america-big"><img src="http://placekitten.com/1989/996" alt="America" /></div>
</div>
<!-- // Animated Map // Europe -->
<div class="viewport-europe hidden">
<div class="compass">
Top
Right
Bottom
Left
</div>
Zoom Out
<div class="instructions"><img src="map/instructions.png" alt="Instructions"></div>
<div class="europe-big"><img src="http://placekitten.com/2000/1000" alt="Europe" /></div>
</div>
<!-- // Animated Map // Asia -->
<div class="viewport-asia hidden">
<div class="compass">
Top
Right
Bottom
Left
</div>
Zoom Out
<div class="instructions"><img src="map/instructions.png" alt="Instructions"></div>
<div class="asia-big"><img src="http://placekitten.com/1999/999" alt="Asia" /></div>
</div>
</div>

You do not need the queue function.
If you want the fadeIn and fadeOut at the same time:
$('.default .asia').click(function(){
$('.default').fadeOut("fast");
$('.viewport-asia').fadeIn("fast");
});
If you want the fadeOut first and after it finishes the fadeIn:
$('.default .asia').click(function(){
$('.default').fadeOut("fast", function(){
$('.viewport-asia').fadeIn("fast");
});
});

Related

JQuery hide() not persisting after hide event

I'm trying to hide a visible section then show a hidden section using JQuery .hide() and .show(). When the event fires (on clicking an image) it only hides the visible section momentarily, then becomes visible again with the previously hidden section now visible below the first visible section. Based on the docs I've read and some tutorials I've watched this shouldn't be happening.
HTML:
<div class="transition-div">
<section class="project-section">
<div class="project-wrapper" id="project-one">
<div class="desc-text">
<h2>Header</h2>
</div>
<div class="project-image-wrapper">
<img class="project-image" id="project-img-one" src="images/img1.png">
<button class="project-button">Button
</button>
</div>
</div>
</section>
<section class="project-section hidden">
<div class="project-wrapper">
<div class="desc-text">
<h2>Header</h2>
<p>Some description text</p>
</div>
<div class="project-image-wrapper">
<img class="project-image" src="images/img1.png">
</div>
</div>
</section>
</div>
JS:
$('.hidden').hide();
var slideSection = function() {
$('.project-image-wrapper').click(function() {
var $parentDiv = $(this).parents('.transition-div');
var $childToShow = $parentDiv.find('.hidden');
var $childToHide = $childToShow.siblings('.project-section');
$childToHide.hide(300, hideActiveSection());
function hideActiveSection() {
$childToHide.addClass('hidden');
$childToShow.show(300, function() {
$(this).removeClass('hidden');
});
}
});
};
slideSection();
How would I get the section I want to hide to do so persistently until I click the currently visible project image to show it? Could my CSS be interfering with what I want to do here? If so I'll post the code. Thanks!

Making automatic transition slideshow out of previously designed gallery

As title states, the website I have currently has a "click to go to next image" slide show as the banner image. I'm looking to turn it into a slideshow that automatically transitions from image to image but I'm not sure exactly how to do it.
The site can be found # rdesignmedia.com/testing/logo_you
The code is as follows:
<div class="camera_container">
<div class="camera_wrap" id="camera">
<div data-src="images/page-1_slide1.jpg">
<div class="camera_caption fadeIn">
<div class="jumbotron jumbotron1">
<em>On Tour</em>
<div class="wrap">
<p>Engineered Elegance</p>
</div>
</div>
</div>
</div>
<div data-src="images/page-1_slide2.jpg">
<div class="camera_caption fadeIn">
<div class="jumbotron jumbotron2">
<em>ELEVATE</em>
<div class="wrap">
<p>Your Brand Lives Here.</p>
</div>
</div>
</div>
</div>
<div data-src="images/page-1_slide3.jpg">
<div class="camera_caption fadeIn">
<div class="jumbotron">
<em>Tech Branding</em>
<div class="wrap">
<p>Stand out from the crowd with technological branding</p>
</div>
</div>
</div>
</div>
</div>
</div>
Looking at the site you can do this after the page loads:
// Creates an interval that runs the function every 2 seconds
setInterval(
function () {
// Finds the ul holding the little dots
var ul = $(".camera_pag_ul");
// Finds the currently selected dot
var selected = ul.find('.cameracurrent');
// Finds the next dot to click
var next = selected.next('li');
// If the next dot exists click it, else start over with first one
if (next.length != 0) {
next.click();
}
else {
ul.find('li:first').click();
}
}, 2000
);
This works if I run it in the console on the site. This switches the image every 2 seconds. You can obviously change the 2000 to something else to increase the time the images is displayed before the next one shows.

Detecting whether mouse is in an element with jQuery

I have a web page that uses jQuery. My page looks something like this:
<div id="page">
<!-- Stuff here -->
<div id="content">
<div class="row">
<div class="col"><!-- stuff --></div>
<div class="col"><!-- stuff --></div>
<div class="col"><!-- stuff --></div>
<div class="col"><!-- stuff --></div>
</div>
<div class="row">
<div class="col"><!-- stuff --></div>
<div class="col"><!-- stuff --></div>
<div class="col"><!-- stuff --></div>
</div>
</div>
<!-- Stuff here -->
</div>
<div id="note" style="display:none;">
<!-- stuff here -->
</div>
var noteTimeout = null;
var note = $('#note');
$(".row")
.mouseover(function () {
var col = $(this).find('.col:last');
var p = col.position();
note.css({zIndex:1000, top: p.top, left: (p.left + col.width() - note.width()/2) });
note.show();
})
.mouseout(function (e) {
if (noteTimeout != null) {
clearTimeout(noteTimeout);
}
noteTimeout = setTimeout(function () {
note.fadeOut(150);
}, 250);
})
;
Basically, when a user hovers over a row, I'm trying to show a note in the last column of the row. If a user moves to another row, the note moves to that row. However, if the user's mouse is outside of the "content" area, I want to hide the note after 250 milliseconds. The last requirement is causing me problems.
As it is, the note disappears after 250 milliseconds if I change rows. However, if I remove the timeout, the note flickers if a user moves their mouse over it.
You want to use .hover for the element (in this case an array of elements) which detects as the mouse enters and leaves. It's an expansion of the functionality of .mouseenter() & .mouseleave().
This is will make it so that whilst the mouse is over the element it will do something rather than .mouseover which simply triggers an event.
This is explained further by Navin Rauniyar here

fadein fadeout jquery on mouse-over

I have three sections with a default logo...left,middle and right..on mouse over all sections are changing one by one with their own respective logo.
When I mouse-over the left section it has changed with its logo but the problem is when I mouse-over that logo on left section its turned into the default section ( means left section vanished along with its logo)that I don't want.
I need the mouse effect will be Off when i mouse-over the left section logo, same thing will be applicable on the other two section..
The Html :
<div id="container">
<div class="logo">
<img src="http://wphooper.com/svg/examples/circle_filled_with_pattern.svg">
</div>
<div class="main" id="left">
<div class="dot1-top">
<img src="http://www.subblue.com/assets/0000/2881/circle-guide_square.gif" width="53" height="52" alt="">
</div>
<div class="showhide">
<div class="main1 hide" style="background-image:url(http://bestwallpaperhd.com/wp-content/uploads/2012/12/vector-art-background.jpg)"></div>
</div>
</div>
<div class="main" id="middle">
<div class="dot2-top"><img src="http://www.subblue.com/assets/0000/2881/circle-guide_square.gif" width="53" height="52" alt=""></div>
<div class="showhide2">
<div class="main2 hide2" style="background-image:url(http://www.vectorfree.com/media/vectors/yellow-background-red-swirl.jpg)">
</div>
</div>
</div>
<div class="main" id="right">
<div class="dot3-top"><img src="http://www.subblue.com/assets/0000/2881/circle-guide_square.gif" width="53" height="52" alt=""></div>
<div class="showhide3">
<div class="main3 hide3" style="background-image:url(http://hdwallpaper2013.com/wp-content/uploads/2012/12/Windows-7-Background-HD-Wallpaper-1080x675.jpg)">
</div>
</div>
</div>
</div>
And Here's the jsfiddle
You need to add a hover effect on the class logo-middle.
e.g.
$(".logo-middle").hover(function mouseIsOverImage() {
/* keep the image */
}, function mouseIsOffImage() {
/* make the image what it was before */
});
By the way, you also should adjust your hover functions to clear the animation queue. If you quickly mouse over and off of the sections several times you'll see that there are many animations that get queued up and then all continue run until they're done. $.clearQueue() should do the trick.
I'm not sure if this is what you need but I did a little cleanup to your markup and CSS and came up with this solution for the hover effects
$('.bg').hide();
$('.main').hover(function (){
$(this).siblings('.main').find('.bg').stop().fadeOut();
$(this).find('.bg').stop().fadeIn();
$('#logo img').attr('src',$(this).data('logo'));
}, function () {});
$('#container').mouseleave(function(){
$('#logo img').attr('src',$(this).data('logo'));
$('.main .bg').stop().fadeOut();
});
You can check the updated fiddle here

Overriding preceding function in javascript

Say I have many div "pages" set up like this:
<script type="text/javascript">
$('.link').on('click', function(e){
fadeOutPage();
$(this.getAttribute("href")).fadeIn(); //fade in clicked page
});
function fadeOutPage() {
$('#container>div').fadeOut(); //fade out all displayed pages
}
</script>
page 1
page 2
page 3
....
....
<div id="container">
<div id="page1">
<div class="navbar"> contents of navbar 1 </div>
<div class="pagecontents"> contents of page 1 </div>
<div class="pagefooter"> more contents for page 1 </div>
</div>
<div id="page2">
<div class="navbar"> contents of navbar 2 </div>
<div class="pagecontents"> contents of page 2 </div>
<div class="pagefooter"> more contents for page 2 </div>
</div>
<div id="page3">
<div class="navbar"> contents of navbar 3 </div>
<div class="pagecontents"> contents of page 3 </div>
<div class="pagefooter"> more contents for page 3 </div>
</div>
...
...
</div>
This works as I intend it, fade out all pages then fade in the clicked page when I click a link. But I want to delay the fade in of ".pagefooter", for let's say 1000ms, but keep ".pagefooter" inside the parent div "#pageX". Right now when I call "$(this.getAttribute("href")).fadeIn();" it will fade in "#pageX" all at the same time.
How do I override that so I can insert a settimeout(function() {('.pagefooter').fadeIn()},1000) somewhere, so that everything else except ".pagefooter" fades in normally, then ".pagefooter" fades in 1000ms afterwards?
EDIT: Here you go:
$('#page1').show().find('div').hide().filter(function () {
return !$(this).hasClass('pagefooter');
}).fadeIn().add('.pagefooter').delay(1000).fadeIn();
Here's a working demo: http://jsfiddle.net/mFjg5/1

Categories