I am currently coding my personal website and could really need some help with the jQuery.
I wanted the sticky navigation to change it's background color once it passes the header section, for that I've used the jQuery WayPoint plugin.
Then I defined some special css for the content above and the content under the header section. So far the background and font color changes, the .active class link and the color of the .navbar-brand however doesn't change.
Is something wrong in the following script?
$navbar.find('.navbar-brand').animate({color:'white'},500);
$navbrand.css({font-weight:"normal"});
$navbar.find('.navbar-brand').animate({color:'white'},500);
$navbrand.css({font-weight:"normal"});
If yes, then I'd really appreciate a explanation why it is not working.
Here is the full code:
$('#navchange').waypoint(function() {
var $navbar = $("#changenav");
var $navbrand = $("active > a:focus");
if($(window).scrollTop() < $('#navchange').css("top").replace("px", "")) {
// Above
$navbar.animate({backgroundColor:'transparent'},300);
$navbar.find('a').animate({color:'white'},500);
$navbar.find('.navbar-brand').animate({color:'white'},500);
$navbrand.css({font-weight:"normal"});
} else {
$navbar.animate({backgroundColor:'#FFFFFF'},500);
$navbar.find('a:link').animate({color:'#1abc9c'},500);
$navbar.find('.navbar-brand').animate({color:'#1abc9c'},500);
$navbrand.css({font-weight:"bold"});
}
});
And here is a link to my website.
You have some syntax errors.
You should quote the css attributes in .css.
$navbrand.css({"font-weight":"normal"});
$navbrand.css({"font-weight":"bold"});
You are also missing a period in your $navbrand selector.
var $navbrand = $(".active > a:focus");
Related
in this site https://gptrading.it/ i would like to change the time of the transition of the header background hover on scroll. It starts between like two scroll, i would like to make it start right after the first scroll. How can i achive that?
Thank you
If you provide us with a code we can help you. Otherwise it is impossible to know what are you doing exactly.
In advance, it seems that is something related to window.offset() in your javascript function.
EDIT
I have search on your project through JS files. It seems that you are creating a wordpress project. So often the themes you download to install on your wordpress include a theme.js. Here is the path of your theme JS file:
https://gptrading.it/wp-content/themes/techno/assets/js/theme.js?ver=3.2.4
I paste following the code that this file is using to turn the navigation bar into sticky:
// 6.EM STIKY NAV
var headers1 = $('.trp_nav_area');
$(window).on('scroll', function () {
if ($(window).scrollTop() > 200) {
headers1.addClass('hbg2');
} else {
headers1.removeClass('hbg2');
}
});
Just search on this file and replace the value $(window).scrollTop() > 200 with your preference (as you say 0). Remeber that this value is mesured in PX.
I am trying to properly implement a push-side menu plugin (Responsive Menu) into a wordpress theme. Based on SO #Congrim answer, I've managed to achieve a way to lock the body at scroll when push-menu is open (with all the elements including the header fixed) except the interactive links class=edge-ils edge-ils-with-scroll edge-ils-light which will still go Up at push-menu open.
I've saved this sequence into congrim.js file, I've enqueued the script into the theme in functions.php file:
function lockScroll() {
if ($('body').hasClass('lock-scroll')) {
$('body').removeClass('lock-scroll');
}
else {
$('body').addClass('lock-scroll');
}
}
/* I've implemented `onclick="lockScroll();"` in button element,
* using this sequence in the same congrim.js file:
*/
$(document).ready(function() {
$('#responsive-menu-pro-button').click(function() {
lockScroll();
});
});
Removing the jQuery wrap will not give any error in browser console (tested in Chrome) may be still a bad approach to wrapp the code like this in wordpress (?)
In these conditions, unfortunately, overflow: hidden; doesn't apply, at push-side menu open, I can't use this class in CSS file/section:
.lock-scroll {
overflow: hidden;
}
The code will allow me to use only
.lock-scroll {
position: fixed;
}
The question:
Is there any possibility to force the code to implement overflow: hidden;* OR any other a workaround in order to have the interactive links class=edge-ils edge-ils-with-scroll edge-ils-light not going up at push-side menu open, to remain fixed at the position the viewer is clicked before opening the menu?
Please focus on the interactive links issue only, the rest of the scene is fine (header and the logo are in place like it should be, the background pictures are acting like it should as well).
LE: *overflow: hidden; it looks like will produce an unwanted body shifting effect at menu open/close, during the show/hide scrollbar, which is not happening in this stage.
LE2: congrim.js file has been replaced with body-lock.min.js by Outsource WordPress, please see the solution below.
Website testpage here.
Please check the solution given below.
Step 1: Add this CSS .scroll-lock{position:fixed !important;}.
Step 2: Add this JS.
$(document).ready(function() {
var windowTop = 0;
var menuOpen = 0;
var offsetContainerList = 0;
$('#responsive-menu-pro-button').click(function() {
var offsetScrollList = $('.edge-ils-item-link:first').offset().top;
if ($('html').hasClass('scroll-lock')) {
$('#responsive-menu-pro-container').one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",
function(event) {
if (menuOpen==0) {
menuOpen = 1;
$('html').removeClass('scroll-lock');
$('.edge-ils-content-table').css('top', eval(offsetContainerList)-40+'px'); //change image container top position
$('html').scrollTop(windowTop); //scroll to original position
}
else {
menuOpen = 0;
}
});
}
else {
windowTop = $(window).scrollTop();
offsetContainerList = $('.edge-ils-content-table').offset().top;
$('html').addClass('scroll-lock');
$('.edge-ils-content-table').css('top', -offsetScrollList + 'px'); //change image container top position
}
});
});
That's it!
Please add the below code in your custom js file .
jQuery('#responsive-menu-pro-button').click(function(){
var menu_active = jQuery(this).hasClass('is-active');
if(menu_active){
jQuery('body').css('position','fixed');
}else{
jQuery('body').css('position','static');
}
});
I hope it helps you.
Thanks
Your scroll isn't a natural navigator-based scroll, you have a JS somewhere swapping classes to emulate a scroll (edge-appeared,edge-up,edge-down).
On the push-side menu opening, these classes are reset, overflow-hidden won't change that.
You need to find which JavaScript is swapping those classes and prevent it from doing so, I'd be glad to be of further help but you have so many JS files that it would take quite some time to go through all of these. If you succeed in making a Minimal, Complete, and Verifiable example please post it here.
I am trying to create a very low specificity css property using javascript. Just like !unimportant (which doesn't exists)
I don't know whether this is possible or not.
My reason to look for something like !unimportant is that I am writing a small javascript plugin. In which I want to add a default style to a element which should be later easily overriden by the user.
But if I write:
element.style.backgroundColor = "green";
The user will not be able to override the above style easily without using !important. So, I added a dynamic style tag by using the following code:
var style = document.createElement('style');
// WebKit hack :(
style.appendChild(document.createTextNode(""));
document.head.appendChild(style);
and then to the above code, I added a dynamic stylesheet using the following code:
var element = document.getElementById('main');
// To use attribute names to apply the styles
element.setAttribute('custom-el', '1');
var sheet = style.sheet;
var properties = "background-color: green;";
var elName = "[custom-el]";
if (sheet.insertRule) {
sheet.insertRule(elName + "{" + properties + "}", 0);
} else if (sheet.addRule) {
sheet.addRule(elName, properties, 0);
}
Now the background-color: green can be overriden by using the following code:
div.main {
background-color: red;
}
But as you can see in css, I used higher specificity to override background-color: green i.e div + .green.
But I want the overriden to happen even when user writes the following css:
.main{ /* Could be simple class name or id name or even tag name */
background-color: red;
}
Fiddle
This might seems to be a small issue. but it is a big problem for me. Please help.
I would simply write like this:
element.style.backgroundColor = element.style.backgroundColor || "green";
Where, if backgroundColor is undefined then it uses green as backgroundColor else it would take the backgroundColor from stylesheet.
Finally I got the answer..
document.head.insertBefore(style, document.head.children[0]);
I should just insert the dynamic stylesheet above already present stylesheets in the head tag.
Working Fiddle
Unfortunately, this is not working in any IE version. I am still looking for answer.
I made in javascript navbar transition, so when i scroll down background color of navbar is changed. Everything works fine except navbar links, i made a new id for links but just first link changes the color and other are not.
var topbar, containtogrid, menulink, yPos;
function yScroll(){
topbar = document.getElementById('topbar');
containtogrid = document.getElementById('containtogrid');
menulink = document.getElementById('menulink');
yPos = window.pageYOffset;
if(yPos > 150){
topbar.style.backgroundColor = "#484848";
containtogrid.style.backgroundColor = "#484848";
menulink.style.backgroundColor = "#484848";
} else {
topbar.style.backgroundColor = "#00A7B7";
containtogrid.style.backgroundColor = "#00A7B7";
menulink.style.backgroundColor = "#00A7B7";
}
}
window.addEventListener("scroll", yScroll);
This is the code: http://codepen.io/anon/pen/vEgVQy
I am using sass so that is why there is lot of css, just scroll down to end of the css.
So I forked your codepen and made the transition work.
I will explain the steps that I undertook:
I removed the id #menulink from the navbar links. Please note that IDs can only be used for one element. That's also why you only changed the first link on your page.
I simply set the background color of the links to transparent in order to make the color change of the topbar visible.
I removed the JavaScript-code that deals with the elements that have menulink-IDs as I removed them in the HTML.
So in my codepen the transition works but for the perfect result you might also apply changes to the mouseover styles and the dropdown elements.
Hope I was able to help you!
I'm making a website and have "borders" around my main content. I say "borders" because its not a CSS border, but div's with a background image.
Now I have my left and right div borders (#cont-border-left/right) height set explicitly to 675px, and I have another div (#extend-l/r) just under that which I want to expand down the page when the main content goes past 675px.
I'd like to to this using only CSS if possible, but if not JavaScript/JQuery would be a great solution for me as well.
I was going to paste a bunch of the code here, but it would probably just be easier to view the source, because I think it will make more sense if you can see it all together.
Saw this on a similar question... But I'm not great with jQuery or JavaScript.
$(document).ready(function()
{
if($('#leftColumn').height() > $('#rightColumn').height())
{
$('#rightColumn').height($('#leftColumn').height());
}
else
{
$('#leftColumn').height($('#rightColumn').height());
}
});
And turn it into something like:
$(document).ready(function()
{
if($('#content').height() > $('#cont-border-left').height())
{
$('#extend-l').height = $('#content' - 645px)
^The above line needs help / correcting
}
else
{
$('#extend-l').height = 0
}
});
Any ideas on what I should try out?
EDIT2: Still would like to know if someone has a pure CSS solution!
You might be interested in CSS3 border-images. See various:
css3.info: Border-image: using images for your border
css-tricks.com: Understanding border-image
border-image-generator
border-image
Figured it out. I was close with the edit I made.
Heres the work code should anyone need something similar in the future.
$(document).ready(function()
{
if($('#content').height() > $('#cont-border-left').height())
{
$('#extend-l').height($('#content').height()-675)
}
if($('#content').height() > $('#cont-border-right').height())
{
$('#extend-r').height($('#content').height()-675)
}
});