//その2
function Elevator_cuddleHeight (position) {
var ary_cuddle_height = ['top', 'middle', 'bottom'];
var type_no;
if (! position)
position = 'top';
type_no = ary_cuddle_height.indexOf (position.toLowerCase ());
if (0 > type_no)
throw new Error ('指定できない値');
return type_no;
}
function Elevator_cuddleWidth (position) {
var ary_cuddle_width = ['left', 'center', 'right'];
var type_no;
if (! position)
position = 'left';
type_no = ary_cuddle_width.indexOf (position.toLowerCase ());
if (0 > type_no)
throw new Error ('指定できない値');
return type_no;
}
Elevator.prototype.start = Elevator_start;
Elevator.prototype.stop = Elevator_stop;
//_______________________________________
var Manager = new function () {
var stocker = new Singleton;
var ary_cuddle_height = ['top', 'middle', 'bottom'];
var ary_cuddle_width = ['left', 'center', 'right'];
this.handleEvent =
(function (event) {
switch (event.type) {
case 'scroll' :
stocker.getAllOptions().forEach (function (obj) { obj.method ('start'); });
break;
case 'unload' :
document.removeEventListener ('scroll', this, false);
window.removeEventListener ('unload', this, false);
break;
}
});
this.create =
(function (target, parm, cbFunc, cbObject) {
if (1 > arguments.length)
return null;
if (stocker.contains (target))
return stocker.getOption (target);
var elevator = new Elevator (target, {
'accell' : parm.accell || 2,
'interval' : parm.interval || 50,
'cuddleHeight': Elevator_cuddleHeight (parm.cuddleHeight),
'cuddleWidth' : Elevator_cuddleWidth (parm.cuddleWidth),
'offsetY' : parm.offsetY || 0,
'offsetX' : parm.offsetX || 0
}, cbFunc, cbObject);
target.style.position = 'absolute';
elevator.start ();
var controller = Controller (elevator);
stocker.add (target, controller);
return controller;
});
document.addEventListener ('scroll', this, false);
window.addEventListener ('unload', this, false);
};
this.Elevator = Manager;
})();
var li = document.querySelectorAll ('li');
Elevator.create (li[0], {accell:4, interval: 10 });
Elevator.create (li[1], {accell:8, interval: 10, cuddleWidth: 'center' });
Elevator.create (li[2], {accell:12, interval: 10, cuddleWidth: 'right' });
Elevator.create (li[3], {accell:16, interval: 10, cuddleHeight: 'middle', cuddleWidth: 'right' });
Elevator.create (li[4], {accell:20, interval: 10, cuddleHeight: 'bottom', cuddleWidth: 'right' });
Elevator.create (li[5], {accell:24, interval: 10, cuddleHeight: 'bottom', cuddleWidth: 'center' });
Elevator.create (li[6], {accell:28, interval: 10, cuddleHeight: 'bottom'});
Elevator.create (li[7], {accell:32, interval: 10, cuddleHeight: 'middle'});
Elevator.create (li[8], {accell:36, interval: 10, cuddleHeight: 'middle', cuddleWidth: 'center' });
</script>
しほうはっぽうに、せっていできた~!
お礼
こちらもすばらしいですね。 参考にさせていただきます。