How to persist checking the screen width in Javascript
Tags: javascript,jquery,css
Problem :
I have a function that runs on document ready. What it does is depending on if a certain link is showing on the nav bar, it will set the CSS for all the other links to keep the spacing aligned.
The way I have it written, it will only run on the first DOM load and if you resize it, it will look unaligned at a smaller breakpoints.
My question is how do I constantly run this function depending on the size of the window. Even if the user resizes it, it will run the function and set the correct CSS.
Is this possible?
Let me know! Thanks!
$(document).ready(function () {
var link = $('#catNav-sale').css('display');
var winWidth = $(window).width();
if (SaleLinkCSS == 'block')
{
if (winWidth >= 975)
{
$('#ID').css('left', '185px');
}
else
{
}
}
Solution :
You could try any of the following,
Vanilla
window.onresize = function(event) {
/** Your code here. **/
};
jQuery
$(window).resize(function() {
/** Your code here. **/
});
or A CSS option would be to use media queries.
Reading Material
CSS Howto..
You can replace your print code with this one : print " <tr > <td > $count. <a href=\"$breweryURL\"> $brewR</a> </td> <td style=\"position: relative;\"> <img style=\"z-index: 8;\" src=\"blueBar.png\" width=\"$width\" height=\"$height\">...
Try: #ctl00_ContentPlaceHolder1_Area div[id^="ctl00_ctl00_ContentPlaceHolder1_"] { display: inline !important } If that works, see if it works without !important, which is bad practise. Demo: http://jsfiddle.net/thirtydot/RGAm8/...
Use CSS3 box-shadow property. Example: input[type=text] { box-shadow: inset 2px 2px 2px 2px black; } ...
You can't do it that way. CSS classes are hierarchical so: .button.details will only work for a structure like the following: <div class="button"> <div class="details"> </div> </div> It means for...
HTML: <input type="text" name="firstname" title="First Name" style="color:#888;" value="First Name" onfocus="inputFocus(this)" onblur="inputBlur(this)" /> JavaScript: function inputFocus(i){ if(i.value==i.defaultValue){ i.value=""; i.style.color="#000"; } } function inputBlur(i){ if(i.value==""){...
The css styles for these arrows are the following ones: .mm-prev:before, .mm-next:after, .mm-arrow:after { content: ''; border: 2px solid transparent; display: inline-block; width: 8px; height: 8px; margin: auto; position: absolute;...
You can store click state in Meteor.Collection. Changes in collections propagate reactively for all connected clients. Just create separate document for each square and save state here. Then you can...
You can take some actions to override the style: One be sure your CSS is loaded after the bootstrap. Two write your class at the end of the file. Three...
I solved enabling flexbox. After raising an issue in Bootstrap's Github repository I got an answer by a Bootstrap member: The .col-xs-4 isn't as tall as the .col-xs-8, so there's...
:first-of-type will look here for first appearance of a tag, here input or label and will select it if it has also the class . here your first-of-type input has...
Here is solution. It's called zig-zag border. http://jsfiddle.net/justinmc/QqnD3/ <div class="container"> <h1>Content Here</h1> </div> .container { position: relative; padding: 8px 8px 32px 8px; background: #dddccf; } .container:after { background: linear-gradient(-45deg, #ffffff...
You can use display: table for this. Write like this: div.WhiteZone { color: #000; background-color: #fff; display: table; } div.Box { padding: 0px; text-align: center; display: table-cell; } Check this...
Try this: body { background: url(../images/bg.jpg) no-repeat; -webkit-background-size: cover; /*-- Used for Chrome and Safari browsers --*/ -moz-background-size: cover; /*-- Used for Firefox browser --*/ -o-background-size: cover; /*-- Used for...
background-size: cover is what you need. There is a good article here on scaling: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Background_and_Borders/Scaling_background_images Try this... html <div id="slideshow"> <div class="sub-menu"><img src="/wp-content/themes/wpbootstrap/images/logo-arrow.png"...
Have you tried IE9.js ? http://code.google.com/p/ie7-js/ http://www.charlescooke.me.uk/web/lab_notes/ie7_script.html http://ie7-js.googlecode.com/svn/test/index.html http://ie7-js.googlecode.com/svn/test/checked.html ...
CSS: body { background: url("http://www.wohn-blogger.de/wp-content/themes/itheme2/skins/gray/images/body-bg.png") repeat scroll 0 0 #D1D1D1; color: #666666; } ...
Flexible box technique is apt for the problem. Set the parent container to be the flexible box. Target the left and right elements to have a fixed width using flex:...
I'm not sure you need to worry about a special data attribute as it's possible to achieve the line number using pure CSS and the counter-increment property. Having the hyperlink...
Instead of choosing display:inline for your li you could keep them as blocks and do this: li { float:left; } Then you could play with the margins to space them...
Instead of using absolute positioning on the div, you can add a margin-left value of 10%, which will position the div in the same place and allow the other content...
Instead you can override some properties of default clases of bootstrap with .init class and use bootstrap alert message like this: .init { border:2px solid #EEEEEE; font:14px/1.3 Verdana,"Lucida Grande",Arial,Helvetica,Sans-Serif; margin:0px;...
The thing you have to keep in mind is that the opacity property will affect the opacity of the entire element, including its text/children. If you want to affect JUST...
If I understand correctly what you mean (to move logo of Lamborghini without that strange effect of heading), then you may try to use this (copied from answer to question...
div#container { height: 275px; width: 1000px; overflow: auto; white-space: nowrap; } div#container span.block { width: 300px; display: inline-block; } The trick here is only elements that behave as inline by...
I create a white right triangle with the same height and width of the button, alpha level of 70% and place it as background image background: url(file:///home/juanpa/Public/a/img/Ontario.png) left no-repeat; that's...
you can achieve the desire effect just using one single div. Check the DEMO. div{border:1px solid gray; width:28px; height:28px; position:relative;} div:after{ content:""; position:absolute; border-top:1px solid red; width:40px; transform: rotate(45deg); transform-origin:...
Make the line-height of the div the same as the height of the div, eg: #UploadSuccess { height: 20px; line-height: 20px; } This will only work if you have one...
You havn't posted your full html so I don't know what your img tags look like. But assuming you have given them an id (id="someId"), do this: $("#someId").click(function(){ $(".logo").fadeToggle("fast"); });...
Your problem is caused by the fact that your columns are floating. Take a look at 'Clearfix'
If you don't mind some markup change: http://jsfiddle.net/BMEXR/30/ HTML: <div class="parent"> <div class="childContainer"> <div class="childContents"> <a href="">First Page</a><a href="">Second Page</a><a href="">Third Page</a> </div> </div> </div>...