I use JQuery : 1.6.4
My target it's create function who, without giving varabiles in (), can start and stop Script.
When i tried reach.. target.. I was found a few problems...
Specyfic variable\s only for JQuery plugin, with acces from funcions (change variables)
functions move_text
Result for div 190px , and distance 2.5px
190, 187.5, 190... We can.. se fault change of global variable
Should be 190, 187.5, 185...
How resolve this problem (JSON ? Window)?
I tried way with JSON, object... but... i waste a lot of time.. And nothing find...
So.. Way with window['distance_iv'] is Good?
Here is my code :
$.fn.emulate_marquee = function( options ) {
var settings = {
'ob_name': '', // object who we use...
'direction': 'left',
'scroll_amount': 100,
'delay': 25 // Animation speed
};
//call in the default otions
options = $.extend(settings, options);
return this.each(function(options) {
var object = $(settings.ob_name);
window['distance_ob'] = width = object.width();
//object.css(settings.direction , width + 'px'); // Set Width
//alert(width);
total_width = (2 * width) / settings.scroll_amount;
// total_width
settings.distance = settings.scroll_amount / (1000/ settings.delay); // Calculate distance for one frame
width_s = screen.width; // Get screen width
next_obj = setTimeout (function(){
move_text()
}, 1);
/*next_res = setTimeout (function(){
resolution_ch()
}, 1);
*/
var move_text = function()
{
//alert((settings.width - (i * settings.scroll_amount)) + 'px');
alert(window['distance_ob'] + 'px');
window['distance_ob'] -= settings.distance;
object.css(settings.direction , window['distance_ob'] + 'px');
alert(window['distance_ob'] + 'px');
if (window['distance_ob'] < total_width)
{
next_obj = setTimeout (function(){
move_text()
}, settings.delay);
}
else
{
next_obj = setTimeout (function(){
move_text()
}, settings.delay);
window['distance_ob'] = width;
}
}
var resolution_ch = function()
{
if (screen.width != width_s)
{
// change varabiales... for new resolution
width_s = screen.width;
distance_ob = width = object.width();
alert(width_s + ' ' + object.width());
total_width = (2 * width) / settings.scroll_amoun;
alert("Detected Change resolution.... nuke in 5 second... started...");
}
next_res = setTimeout (function(){
resolution_ch()
}, 1000);
}
});
};
window['distance_ob']
is working and you're wondering if there is a better way? – mu is too short Oct 8 '11 at 21:55