Damian Toczek
Damian Toczek

Reputation: 63

How to create a dynamic variable that show the actual value?

i've created a JavaScript Code that is doing what i want but it doesn't keep the "var" actual.

It should change the float of <nav> when the <header>'s height is greater than 51px. But it doesnt take anny effect when you resize the window. It works when i "refresh" the page, it should change the "float" "on the fly". That means when someone shrinks the window it should change and not when you refresh the page.

    var clientHeight = document.getElementById('header').clientHeight;
if (clientHeight < 51) {
 document.getElementById('nav').style.float = "right";
}
else {
 document.getElementById('nav').style.float = "left";
}

jsFiddle

Upvotes: 0

Views: 49

Answers (1)

Mohamed Noor
Mohamed Noor

Reputation: 115

The problem in your code is that the jsfiddle using HTTPS and your link is using HTTP, the browser will block this request since it's not secure:

enter image description here

If you have HTTPS on your website instead of putting http://damina... put //damina (without https or http then the browser will load the iframe according to the main website) or https://damina

Hope this helps.

Upvotes: 1

Related Questions