Jump to content
Larry Ullman's Book Forums

benjamin.morgan

Members
  • Posts

    38
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by benjamin.morgan

  1. Thanks! I appreciate it. I guess it is just something with jsFiddle. I think I will start using codepen http://codepen.io/joe/pen/odfib
  2. I tried to do that! http://jsfiddle.net/98d6X/4/ but it didn't work . It should be a global variable. This is what I meant with the first part. I had to change this. http://awesomescreenshot.com/076pvoa39
  3. Solved. Thanks HartleySan. It was the window.onload causing the problem as well as it being initially set in javascript. I had to choose no wrap instead of onload on the side. I've never had that problem before! http://jsfiddle.net/98d6X/3/ Another problem that came up is if I use var mov = document.getElementById('move'); If i use mov.style.left it doesn't work anymore. I am putting the var mov as a global variable outside of the functions. It will only work if I create the same variable in both functions.
  4. When I add that line it doesn't even set the property. It doesn't even move it 10px to the right. http://jsfiddle.net/98d6X/2/
  5. I am trying to animate some text for learning purposes, which I have done before, and now I can't seem to be able to do it. Basically I have some text positioned relative. It has an property of left: 10px;. In the javascript I want to use setInterval to add 50px every 500ms. I have pasted the code in a jsFiddle. http://jsfiddle.net/98d6X/1/ Why isn't it adding the px or moving?
  6. That's true. I just like looking at other resources, sometimes, it helps me remember the stuff better.
  7. Also make sure if you are echoing out that code that the quotes are escaped for example. Not sure how you have it in the php script. Seeing your php code might help. <php echo "<p id=\"hello\"></p>"; ?>
  8. Just wanted to wish everyone a very Happy Thanksgiving.
  9. The console error in mine and Larry's code is TypeError: target is undefined COOKIE.setCookie('theme', target.id, expire); Here is my cookie code var COOKIE = { setCookie: function(name, value, expire) { 'use strict'; var str = encodeURIComponent(name) + '=' + encodeURIComponent(value); str += ';expires=' + expire.toGMTString(); document.cookie = str; }, getCookie: function(name) { 'use strict'; var len = name.length; var cookies = document.cookie.split(';'); for (var i = 0, count = cookies.length; i < count; i++) { var value = (cookies[i].slice(0,1) == ' ') ? cookies[i].slice(1) : cookies[i]; value = decodeURIComponent(value); if (value.slice(0,len) == name) { return cookies[i].split('=')[1]; } } return false; } };
  10. Okay, I have the code working but I don't under stand it at all. Here is what I am having a problem with. I understand the setTheme function. What starts confusing me is on the window.onload. It calls the setThemeCookie function but what goes in the e variable in the function? Also it says "Close your browser window, or even quit the browser, and then reopen the page to see your theme selection retained." When I close the browser or reopen the page or refresh it, it always goes back to the blank theme. function setTheme(theme) { 'use strict'; var css = null; if (document.getElementById('cssTheme')) { css = document.getElementById('cssTheme'); css.href = 'css/' + theme + '.css' } else { css = document.createElement('link'); css.rel = 'stylesheet'; css.href = 'css/' + theme + '.css'; css.id = 'cssTheme'; document.head.appendChild(css); } } function setThemeCookie(e) { 'use strict'; e = e || window.event; if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } var target = e.target || e.srcElement; var expire = new Date(); expire.setDate(expire.getDate() + 7); COOKIE.setCookie('theme', target.id, expire); setTheme(target.id); return false; } window.onload = function() { 'use strict'; document.getElementById('aTheme').onclick = setThemeCookie; document.getElementById('bTheme').onclick = setThemeCookie; var theme = COOKIE.getCookie('theme'); if (theme) { setThemeCookie(theme); } }; HTML <p>Choose a theme: <a href="somepage.php?theme=a" id="aTheme">A Theme</a> || <a href="somepage.php?theme=b" id="bTheme">B Theme</a></p>
  11. Hey @teachupnorth, how did you access the files? When I emailed them they acted like they didn't know what I was talking about.
×
×
  • Create New...