【发布时间】:2011-10-08 21:49:15
【问题描述】:
我使用 JQuery:1.6.4
我的目标是创建函数,该函数无需在 () 中提供变量,就可以启动和停止脚本。
当我尝试达到.. 目标.. 时发现了一些问题...
仅适用于 JQuery 插件的特定变量,具有来自函数的访问权限(更改变量)
函数 move_text
div 190px 和距离 2.5px 的结果
190, 187.5, 190... 我们可以.. 检测全局变量的错误变化
应该是 190、187.5、185...
如何解决这个问题(JSON?窗口)?
我尝试过使用 JSON 的方式,对象......但是......我浪费了很多时间......但什么也没找到......
那么.. 使用 window['distance_iv'] 的方式好吗?
这是我的代码:
$.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);
}
});
};
【问题讨论】:
-
在 firefox 7 中...故障 190、192.5、190(左:(distance_ob)),函数 move_text ...嗯,这是个好问题
-
/* 小更新评论 */ 在firefox 7等浏览器... 故障190, 192.5, 190, ... (like a 1, 2, 1, 2) (左: (distance_ob )),函数 move_text ... 嗯,所以我尝试找到解决它的好方法
-
移动功能应该适用于 190px div 190, 187.5, 185...
标签: javascript jquery json global-variables