Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Wednesday, August 15, 2012

Setting coordinate/positioning using Javascript

If you ever set positioning in javascript using syntax similar to below and didn't work (in browser standard mode):

var some_div = document.getElementById("some_div");
some_div.style.top  = "30";
some_div.style.left = "30";

What missing is only the unit of measurement when setting top and left position.

var some_div = document.getElementById("some_div");
some_div.style.top  = "30" + "px";
some_div.style.left = "30" + "px";

Friday, March 2, 2012

Bug when combining Twitter Bootstrap Modal and Modernizr using Opera 11.61

I suffer from a bug when using Twitter Bootstrap (TB) Modal and using Modernizr.mq (media queries) functionality, in my case is the animation is not firing using Opera 11.61. The code that I write is:
$(document).ready(function () {
  // firing up notice (modal) after loading
  $('#announcementModal').modal('show');
  
  // I have other purpose on this and just try to do 
  //  console logging to see if that work or not
  if (Modernizr.mq('(min-width: 980px)')) {
    console.log('screwed');
  }  
});
and BAM! The modal animation isn't firing at all. After googling and searching for the bug's solution and found out none, I have a thought on doing this: switching the code like this
$(document).ready(function () {
  // I have other purpose on this and just try to do 
  //  console logging to see if that work or not
  if (Modernizr.mq('(min-width: 980px)')) {
    console.log('screwed');
  }

  // firing up notice (modal) after loading
  $('#announcementModal').modal('show');    
});
And the result? Everything just worked! Can't believe this. I think there's a mechanism in Modernizr to stop all things to make detection more precise and (maybe) they forget to return all the things that they stop. Just my $0.02 though, I kind of busy to deep down the code yet. :(