Different delay on second menu click or close - wordpress

Situation: Wordpress theme mobile menu doesn't extend to the top. Since I have an image in the site header and it gets cut in half right now by the menu I would like to completely cover it by the menu when its open.
The fix: Change transparent-header class to white background on menu click.
My problem: The stock theme menu got an ease transition for closing the menu while my white background disappears nearly immediately. The timing when my white background color disappears is way to fast but the timing on opening the menu is good. So I need a different delay for closing. Do I need to go the if/else route here?
This is what I have right now:
jQuery(document).ready(function($) {
$(".mobile-menu").on("click", function () {
$(".transparent-header").toggleClass("white", 1000);})
});
This is one of the experiments that didn't work
jQuery(document).ready(function($) {
if($(".mobile-menu").hasClass("opened")){ //open function
$(".transparent-header").css("white", 1000);
}else{
$(".transparent-header").css("transparent", 4000);
}
});
Solution: What works for me. I let other decide if this thread should be deleted. I would find it quite helpful.
jQuery(document).ready(function($) {
$(".mobile-menu").on("click", function() {
if (jQuery(this).hasClass("opened")) {
$(".transparent-header").toggleClass("white", 1000);
}
else
{
$(".transparent-header").delay(480).queue(function (next) {
$(this).removeClass("white");
next();})
}
})});

Related

Link with hover overlay is opened on first click on mobile device

I have a div that displays another content on hover using css transitions.
There is one text element <h3>Another Text</h3> that overlays link email adress. On desktop browser it's working correctly - I can click the link after hover is activated. On phone device where hover is replaced by clicking on the element, there's a problem - If I activate the hover by clicking on "Another Text" it opens the link right away.
My question is if there is any way how to restrict link opening on first click.
Ideal scenario on phone device is:
user clicks on "Another text"
hover is activated, link is displayedbut not fired
user click link and link is fired
Here is the code: https://jsfiddle.net/9bc0bcja/2/
I've partially solved it using javscript:
$(".team-social")
.bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",
function(e){
if($(this).hasClass("pointerA")){
if(is_touch_device()){
$(this).removeClass( "pointerA" );
}
}
else{
$(this).addClass( "pointerA" );
}
});
$('.team-social a').click(function() {
if(is_touch_device()){
$(this).parent().removeClass("pointerA");
}
});
It activates pointer-events after transition finishes, so it is not fired right away when I click overlay on phone device.
https://jsfiddle.net/9bc0bcja/4/
added javascript + jquery link
added class .pointerA
added pointer-events:none; to class .team-social
Try this Fiddle.
I simplified your code, keeping only the necessary elements.
This script only operates if you're using a mobile device, which is what you should want for performance reasons.
This code watches the hover event rather than transitionEnd, that way the function trigger timing is not dependent on the length of the transition.
if (is_touch_device()) {
var $wrap = $(".wrap"),
$pw = $wrap.find(".pointer-watch"),
$tc = $pw.find(".transition-container");
$pw.addClass("pointerN");
$('.wrap').hover(function wrapHovered() {
if ($pw.hasClass("pointerN")){
setTimeout(function enablePE() {
$pw.removeClass("pointerN");
}, 0);
}
else if (!$wrap.is(":hover")) {
$pw.addClass("pointerN");
}
});
}

How to set a div to change its background and alpha levels upon scrolling

I am looking at websites for inspiration for my new start ups homepage. I saw https://www.pactcoffee.com/ and their home page features a full background image for the header and the nav bar is transparent then it becomes a solid color nav bar as you scroll down. I have only been able to set up the CSS for the site but I don't understand what to do to have the change in nav bar color.
You can do something like this...
http://jsfiddle.net/ojcqbLr2/
Check the Fiddle to see the rest of the code... like the CSS.
This JS will do this.
$(document).scroll(function () {
var y = $(this).scrollTop();
if (y > 100) {
$('.topMenu').fadeIn();
} else {
$('.topMenu').fadeOut();
} });
By the way, I found this info by search.
Show div on scrollDown after 800px
I just made edits to the code so it was at the top and not bottom.
Best of luck.
I have found that you can set two divs. One of which will be display set to none.
$(document).scroll(function () {
var headerHeight = $('header').height(),
s = $('.nav'),
y = $(this).scrollTop();
if (y > headerHeight) {
$('.navLong').fadeIn();
$('.nav').fadeOut();
} else {
$('.navLong').fadeOut();
$('.nav').fadeIn();
}});
This allows one div to disappear when one appears and vice versa. A working example is can be found in the DEMO

Div Fade-In when on screen (currently auto fading!?) - parallax site

OK, so my problem is that I have a parallax website for a client and they would like a product description to fade-in when they scroll-down the parallax site. The problem I think I have is because the site is effectively one long page, the scripting is getting confused and fading the div in from "opacity:0" when the page is loaded. I have put a long fade-in on the div to understand what is happening and I have also made a rubbish box without proper formatting to test it. I have uploaded a temporary copy of the site (i'm working offline) to show what is happening.
http://ethicalincubator.com/parallax/parallax30.07/index_kmd.php#!images
Thank you for your help everyone!!! :-)
CSS
/* Hide any element */
.hideme {
Opacity:0;
}
HTML
<div
class="hideme fadein-on-view"
style="opacity:0;width:200px;height:80px;background-color:white;">Fade
In</div>
SCRIPT
<script>
// Scroller script for Fade-In when "div" is on screen
$(document).ready(function()
{
/* Every time the window is scrolled ... */
$(window).scroll( function(){
/* Check the location of each desired element */
$('.fadein-on-view').each( function(i){
var
bottom_of_object = $(this).position().top + $(this).outerHeight();
var
bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, fade it it */
if(
bottom_of_window > bottom_of_object ){
$(this).animate({'opacity':'1'},5000);
}
});
});
})
</script>
To check the bottom of the window, instead of using .scrollTop, try window.pageYOffset.
Plus I think you're making the JS work too hard - I would try to calculate the bottom_of_object outside the .scroll() function so that it's not calculating the position every time the user is scrolling.
And for simple fade in/out, I would just do a display:none, .fadeIn().

CSS Position Fixing

I have managed to use the position:fixed setting of CSS/CSS3 before and worked quite well!
I saw this a few days ago and was wondering how did they achieve the effect that happens when you scroll down, where the menu bar is in one position before you scroll and then goes to the top where it locks itself down.
See link - http://www.cssportal.com/ < scroll down on any page and observe the top blue menu.
I have tried to look in the source of the page but I cant make head or tails.
Does anyone know what this effect is called?
It's done with javascript, to add a css class that contains position:fixed and other positioning styles to achieve what you want.
It's not complicated. Here is a jquery plugin: http://stickyjs.com/
This is how I did it a few years ago:
var menu_bar = $("#menu");
var top = menu_bar.offset().top;
var detached = false;
$(window).scroll(function (e) {
if ($(this).scrollTop() >= top) {
if (!detached) {
detached = true;
menu_bar.addClass('fixed');
}
} else {
if (detached) {
detached = false;
menu_bar.removeClass('fixed');
}
}
});

Adding css with jQuery based on class

Seeking a solution to my problem...
I partially found an answer from another thread on here, using this script
$(function () {
$(".myclass").hover(function ()
{}, function ()
{
$(".myclass>li").fadeTo(200, 1)
});
$(".myclass>li").hoverIntent(function ()
{
$(this).attr("id", "current");
$(this).siblings().fadeTo(200, .6);
$(this).fadeTo(300, 1)
}, function ()
{
$(".myclass>li").removeAttr("id");
$(this).fadeTo(200, 1)
})})
When an item in the list is hovered, the script fades all other items out. Original demo is here http://jsbin.com/usobe
This works OK on my site, though the list ( a grid of thumbnails) is part of a bigger slider script, which loads "previews" via ajax. When a list item is clicked a hidden section expands on the page, and the slider script assigns the list item a class "active".
When the hidden section is open I would like the activated thumbnail to remain at 1 opacity, while the rest are faded to .6, exactly as it is with the hover effect using the script above. What I am trying to achieve becomes obvious when you click a thumbnail to activate the ajax script. Is it possible to use the active class to make this happen i.e. if class is not active set to .6 opacity?
Thanks in advance
----EDIT
Thanks everyone for suggestions - I am not having much luck so far! Using the code above, would it be possible to modify it so that when a list item is clicked it holds the specified levels of opacity? That would do nicely, I think. Then I could use onclick I guess to fade all items back to full opacity when the hidden div is closed.
I'm trying to guess how your code work, for what I understand you should do something like this:
// this is the selector that gets the click on the thumbnail
$('li.item').click(function() {
// fade all the thumbnails to op 1.0
$('#li.item').css('opacity', '.6');
// let the active thumbnail to 1.0
$(this).css('opacity', 1);
//show your hidden div
});
Then, when you close the hidden div:
$('div#hiddenDiv').onClose(function()
// about to close
$(this).fadeTo('fast', 1);
});
You could use an on click targeting the zetaThumbs li elements, set the current target to 1 and its siblings to .6
$('.zetaThumbs li').click(function(){
$(this).css({'opacity':1}).siblings().css({'opacity':.6});
})

Resources