js封装中,用this.变量名.length作为循环条件,实现不了循环

蒲小若 2017-08-25 08:07:06

function Slider(opt){
this.elem = opt.dom;
console.log(this.elem)
this.sliders = this.elem.getElementsByClassName("banner");
// console.log(5 < this.sliders.length);
// this.slidersLen = this.sliders.length;

init();
function init(){
renderDom();
}

function renderDom(){
//渲染页面
if (opt.direction == "horizontal") {
for (var i = 0; i < this.sliders.length; i++) {
this.sliders[i].style.position = "relative";
this.style.top = 0;
this.style.left = 0;
}
}

}

function bindDom(){
//绑定事件
}
}

window.onload = function (){
var banner = document.getElementById("container");
new Slider({dom:banner,direction:"horizontal"});
}





出现的问题,求大神
...全文
270 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复

    function Slider(opt) {
        this.elem = opt.dom;
        this.sliders = this.elem.getElementsByClassName("banner");

        this.init();
        this.init = function () {
            renderDom.call(this);
        }

        function renderDom() {
            if (opt.direction == "horizontal") {
                for (var i = 0; i < this.sliders.length; i++) {
                    this.sliders[i].style.position = "relative";
                    this.style.top = 0;
                    this.style.left = 0;
                }
            }

        }

        function bindDom() {
            //绑定事件
        }
    }


Web开发学习资料推荐
extjs开发技巧
easyui datagrid fitColumns:true失效解决办法
天际的海浪 2017-08-25
  • 打赏
  • 举报
回复


function Slider(opt){
	this.elem = opt.dom;
	console.log(this.elem)
	this.sliders = this.elem.getElementsByClassName("banner");
//	console.log(5 < this.sliders.length);
//	this.slidersLen = this.sliders.length;
	var _this = this;

	init();
	function init(){
		renderDom();
	}
	
	function renderDom(){
		//渲染页面
		if (opt.direction == "horizontal") {
			for (var i = 0; i < _this.sliders.length; i++) {
				_this.sliders[i].style.position = "relative";
				_this.sliders[i].style.top = 0;
				_this.sliders[i].style.left = 0;
			}
		}
		
	}
	
	function bindDom(){
		//绑定事件
	}
}

window.onload = function (){
	var banner = document.getElementById("container");
	new Slider({dom:banner,direction:"horizontal"});
}
内容概要:本文研究了一种基于粒子群算法(PSO)与动态窗口法(DWA)相融合的无人机三维动态避障路径规划方法,旨在提升无人机在复杂、动态环境下的自主导航能力。通过将PSO的全局寻优能力与DWA的局部实时避障优势相结合,构建了一种高效的混合路径规划框架,并在Matlab平台上实现了仿真验证。该方法能够有效应对环境移动障碍物的突发干扰,实现从起点到目标点的安全、平滑、最优路径生成,同时兼顾飞行效率与避障可靠性。研究涵盖了算法设计、模型构建、参数优化及三维空间仿真实验,展示了良好的应用前景。; 适合人群:具备一定MATLAB编程基础和路径规划背景知识的科研人员、自动化与无人机相关专业的研究生及工程技术人员。; 使用场景及目标:①应用于复杂城市环境、灾害救援、巡检等动态场景下的无人机自主飞行任务;②为智能无人系统提供高鲁棒性的三维避障解决方案;③作为智能优化算法与实时控制算法融合的研究案例,推动自主导航技术的发展; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注PSO与DWA的接口设计与参数协同机制,并可通过调整环境模型和算法参数进行二次实验,以掌握其在不同工况下的性能表现。

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧