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);
}
});
};
Maybe try saving your global variable to
jQuery.data()(ref)But since it sounds like you might need to access methods from outside of the plugin, I would suggest checking out some different plugin patterns.
Check out this awesome “library” of jQuery plugin patterns.
Especially look at the patterns that save the plugin instance into the jQuery data; which is done by default in all of the widget factory templates. But my personal favorite is the “jquery.namespace.plugin-boilerplate.js”