http://jsfiddle.net/MeoMix/8zg2V/83/
I've got the following jsFiddle. The idea is that when a context menu item which is too long is displayed, it renders with ellipsis, but on mouseover it pans through the text.
The code in question:
//Provides helper methods for non-specific functionality.
define('helpers', [], function () {
'use strict';
return {
scrollElementInsideParent: function(element, parent) {
// Scroll the element if its too long to read.
$(element).mouseover(function () {
var distanceToMove = $(this).width() - $(parent).width();
console.log("My width and parent width:", $(this).width(), $(parent).width());
$(this).animate({
marginLeft: "-" + distanceToMove + "px"
}, {
// Just a feel good value; scales as the text gets longer
duration: 15 * distanceToMove,
easing: 'linear'
});
}).mouseout(function () {
$(this).stop(true).animate({ marginLeft: 0 });
});
}
};
Here I log the element being scrolled upon's width as well as its parents width. The console outputs:
My width and parent width: 360 230
but this seems incorrect when looking at the metrics:
Why is this?