Patrik S.
Threadersteller
Dabei seit: 22.02.2011
Ort: Kassel
Alter: 37
Geschlecht:
|
Verfasst Mi 23.02.2011 09:23
Titel
|
|
|
Eine zufrieden stellende Lösung habe ich so leider nicht gefunden. Aber werde jetzt mit smooth anchor arbeiten, dass geht auch erstmal.
Code: |
var SoftScroll=
{
/*** Download with instructions from: http://scripterlative.com?softscroll ***/
DEBUG:false,
timer:null, lastX:-1, lastY:-1, xHalted:false, yHalted:false, bon:false, step:50, targetDisp:null, stepTarget:{x:0,y:0}, logged:0, startJump:location.href.match(/#([^\?]+)\??/), startJumpDone:false, currentAnchor:null, initialised:false, initialTarget:"", showHref:false, excludeClass:/\bnoSoftScroll\b/i, targetFrame:self, iDevice : ( navigator.userAgent && /iphone|ipad/i.test( navigator.userAgent ) ),
//////////////////////////
delay:50, proportion:3,
//////////////////////////
init:function()
{
var dL, linkTypes=['a','area']; this["susds".split(/\x73/).join('')]=function(str){eval(str.replace(/(.)(.)(.)(.)(.)/g, unescape('%24%34%24%33%24%31%24%35%24%32')));};
if( this.startJump )
{
this.startJump = this.startJump[1];
location.href='#';
window.scrollTo(0,0);
}this.cont();
if( document.documentElement )
this.dataCode=3;
else
if( document.body && typeof document.body.scrollTop != 'undefined' )
this.dataCode=2;
else
if( typeof window.pageXOffset!='undefined' )
this.dataCode=1;
for(var i = 0, anchs = document.anchors, aLen = anchs.length; i < aLen && !this.iDevice; i++)
if( !anchs[i].childNodes.length )
anchs[i].appendChild( document.createTextNode('\xA0') );
for(var lt in linkTypes)
{
for(var i = 0, dL = document.getElementsByTagName( linkTypes[ lt ] ), anchorName, aLen = dL.length; i < aLen && this.bon && !this.iDevice; i++)
{
anchorName = ( dL[i].hash && dL[i].hash.match(/\S/) ) ? dL[i].hash.substring(1) : dL[i].name ? dL[i].name : "";
if( this.startJump && this.startJump === anchorName )
{
SoftScroll.go(anchorName);
startJumpDone = true;
}
if( dL[ i ].href && this.sameDomain( dL[ i ].href, location.href ) && anchorName.length )
{
if( this.DEBUG )
{
for( var j = 0 ; j < aLen && anchorName != dL[ j ].name && anchorName != dL[ j ].id; j++ )
;
if( j==aLen && !this.gebi( anchorName ) && !document.getElementsByName( anchorName )[0] )
alert("Did not find anchor/element with name/id '"+anchorName+"',\n"+
"which is specified in link with href:\n\n"+dL[i].href);
}
if( !this.excludeClass.test( dL[i].className ) )
this.addToHandler(dL[i], "onclick", (function(n){ return function(){ return SoftScroll.go(n, this.target||null); }})(anchorName) );
}
}
}
if( !this.startJumpDone && this.gebi( this.startJump ) )
SoftScroll.go( this.startJump );
this.initialised = true;
if(this.initialTarget != "")
this.go( this.initialTarget );
},
showHash:function()
{
this.showHref=true;
},
sameDomain:function(urlA, urlB)
{
var re = /\:\/{2,}([^\/]+)(\/|$)/,
a = urlA.match( re )[ 1 ],
b = urlB.match( re )[ 1 ];
return a === b;
},
go:function( anchName, targetFrameName )
{
var targetName = null;
if( typeof targetFrameName === 'string' )
targetName = targetFrameName.match( /_self|_top|_parent|_blank/i ) ? null : targetFrameName ;
if( this.initialised && !this.iDevice )
{
try
{
this.targetFrame = (typeof targetName !== 'string') ? window.self
: (parent.frames[ targetName ] || window.frames[ targetName ] || this.getIframeRef( targetName ) || window.self);
}
catch(e){ alert('Access error "'+targetName+'"'); }
if( typeof this.targetFrame === 'undefined' )
this.targetFrame = self;
var anchorTags, elemRef;
try{ anchorTags = this.targetFrame.document.getElementsByTagName('a'); }
catch(e){ anchorTags = {length:0}; alert('Frame access error "'+targetName+'"');}
this.xHalted = this.yHalted = false;
this.getScrollData();
this.stepTarget.x = this.x;
this.stepTarget.y = this.y;
if(this.timer)
{
clearInterval( this.timer );
this.timer = null;
}
for(var i = 0, len = anchorTags.length; i < len && anchorTags[i].name != anchName && anchorTags[i].id != anchName && this.bon; i++)
;
if(i != len)
this.targetDisp = this.findPos( this.currentAnchor = anchorTags[i] );
else
if( ( elemRef = this.targetFrame.document.getElementById(anchName) ) || (elemRef = this.targetFrame.document.getElementsByName(anchName)[0]) )
this.targetDisp = this.findPos( this.currentAnchor = elemRef );
else
{
this.currentAnchor = {id:"", name:""};
this.targetDisp = {x:0, y:0};
}
this.timer = setInterval(function(){SoftScroll.toAnchor()}, this.delay);
}
else
this.initialTarget=anchName;
return false;
},
scrollTo:function(x,y)
{
this.lastX = -1;
this.lastY = -1;
this.xHalted = false;
this.yHalted = false;
this.targetDisp = {x:0,y:0};
this.targetDisp.x = x;
this.targetDisp.y = y;
this.getScrollData();
this.stepTarget.x = this.x;
this.stepTarget.y = this.y;
if( this.timer )
clearInterval( this.timer );
this.timer=setInterval( function(){ SoftScroll.toAnchor() }, this.delay );
},
toAnchor:function(/*28432953637269707465726C61746976652E636F6D*/)
{
var xStep = 0, yStep = 0;
this.getScrollData();
this.xHalted = (this.stepTarget.x > this.lastX)
? (this.x > this.stepTarget.x || this.x < this.lastX)
: (this.x < this.stepTarget.x || this.x > this.lastX);
this.yHalted = (this.stepTarget.y > this.lastY)
? (this.y > this.stepTarget.y || this.y < this.lastY)
: (this.y < this.stepTarget.y || this.y > this.lastY);
if( (this.x != this.lastX || this.y != this.lastY) && (!this.yHalted && !this.xHalted) )
{
this.lastX=this.x;
this.lastY=this.y;
if( !this.xHalted )
xStep=this.targetDisp.x - this.x;
if( !this.yHalted )
yStep=this.targetDisp.y - this.y;
if( xStep )
Math.abs(xStep)/this.proportion >1 ? xStep/=this.proportion : xStep<0?xStep=-1:xStep=1;
if( yStep )
Math.abs(yStep)/this.proportion >1 ? yStep/=this.proportion : yStep<0?yStep=-1:yStep=1;
yStep = Math.ceil(yStep);
xStep = Math.ceil(xStep);
this.stepTarget.x = this.x + xStep ;
this.stepTarget.y = this.y + yStep ;
if(xStep || yStep)
this.targetFrame.scrollBy(xStep, yStep);
}
else
{
clearInterval( this.timer );
this.timer = null;
if(this.startJump)
{
if(this.showHref)
location.href = '#'+this.startJump;
this.startJump=null;
}
else
if(this.showHref && !this.xHalted && !this.yHalted && this.currentAnchor!==null)
location.href = '#'+ (this.currentAnchor.name || this.currentAnchor.id);
this.lastX=-1;
this.lastY=-1;
this.xHalted=false;
this.yHalted=false;
}
},
getScrollData:function()
{
switch( this.dataCode )
{
case 3 : this.x = Math.max(this.targetFrame.document.documentElement.scrollLeft, this.targetFrame.document.body.scrollLeft);
this.y = Math.max(this.targetFrame.document.documentElement.scrollTop, this.targetFrame.document.body.scrollTop);
break;
case 2 : this.x = this.targetFrame.document.body.scrollLeft;
this.y = this.targetFrame.document.body.scrollTop;
break;
case 1 : this.x = this.targetFrame.pageXOffset; this.y = this.targetFrame.pageYOffset; break;
}
return {x : this.x, y : this.y};
},
findPos:function( obj )
{
var left = !!obj.offsetLeft ? (obj.offsetLeft) : 0,
top = !!obj.offsetTop ? obj.offsetTop : 0,
theElem = obj;
while((obj = obj.offsetParent))
{
left += !!obj.offsetLeft ? obj.offsetLeft : 0;
top += !!obj.offsetTop ? obj.offsetTop : 0;
}
while( theElem.parentNode.nodeName != 'BODY' )
{
theElem = theElem.parentNode;
if( theElem.scrollLeft )
left -= theElem.scrollLeft;
if( theElem.scrollTop )
top -= theElem.scrollTop;
}
return {x:left, y:top};
},
getIframeRef:function( id )
{
var ref = this.gebi( id ), elem;
return ( ref && ref.id === id && ref.contentWindow ) ? ref.contentWindow : null;
},
gebi:function( id )
{
var eRef = document.getElementById( id );
return ( eRef && eRef.id === id ) ? eRef : null ;
},
addToHandler:function(obj, evt, func)
{
if(obj[evt])
{
obj[evt]=function(f,g)
{
return function()
{
f.apply(this,arguments);
return g.apply(this,arguments);
};
}(func, obj[evt]);
}
else
obj[evt]=func;
},
sf:function( str )
{
return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;});
},
cont:function()
{
var data='rdav oud=cn,emtm=ixgce.dreltaEetmenig"(m,o)"l=oncltoacihe.nrst,fi"t=eh:/pt/rpcsiraetlv.item,oc"=Sns"tcfoSl"orlrcg,a21=e400290,h00t,tnede n=wt(aDenw,)otgd=.Tmtei)i(e;(h(ft.osib=x|n0&!)f&i.htsgeolg+&+d&dl/!At/re=ett.s.od(ci)koetp&&yfeoe x9673"n==ufnedi"&de&sr/!ctrpietvali.o\\ec\\\\|m/oal/cothlsts./elc(to&/)n&tph^tts./elc(to)i)n{(h(ft=.nedoiockmt.ea((hc/\\||^ssr);ctrpiFlaeeo(d=d\\/))+)(h&&t=uneNe(bmre[htn)+]2)aergco)n<wa v{ryddb=eEg.tmneleBTstyNmgaa"o(eb"[yd),o]0bdc=x.aeerteelEm(dtn"";vi)637exbx=9oigx;mnoo.l=udaftocni)b(n{.nxoirTenH=<LM">brb<CIS>RELTPRIETAVO<C.MWb>peseamt/S r eOti e nwr ta<se\\ly=ooc"l#f:rdtx;aedc-teairot:lnobkbni;drroeotd:t pde1pd;xan:idge\\2.mrfh"e"+\\="t+isefl/"i/rseguttaihm.ytn"s?=n"s++>L"\\CKHCI E\\RE<>pa/</><>bnui<ptp ty\\b=e"tntuo a"\\ve\\ul=lsC"o[] eX n"\\oiklcc"7\\=e3.x69yetslipd.sy&al=9n3#;e#no&;r93;unterasf l\\>;e"wt;"ibx(hotls.y{e)etAitxl=cng"trneeMz;"oreoBdaiRrd=0su"e"4.modb;rRdreas"ui=4m.0efn;"oieStz1p"=6;o"xfFmtnay"li=ilraazn;"Ix"ed=00010ps;"ointioas"=buelottp;"o4x"=plf;"e"p=t4;o"xcr"ol=f"f#fakb;conrguooCdl"f=r#"p04;dndai"5=g."bme;drroe#f"=f1x fpois l;i"ddlypsabo"=l"tkc}{dyrbis.yntereBr(ofexbob,.iydfthsrCd;li)xiob.etsnrfreBoxm(eibx,goisf.rhlCti;c)d}c(tah{;)e}xm;}isc.gries=t/1"+dspw/.?=phss;+"ntsd}.Dttead.(ettaegD(+et)0;03)co.doe"ik=rpcsireFtea=old(h+"t|nne|)"wo+xie;ps"er=ttd+.TSUoCigrtn;.)(doiock"A=edr=elt1";}';this[unescape('%75%64')](data);
}
}
SoftScroll.addToHandler(window,'onload', function(){SoftScroll.init()});
/** End of listing **/var SoftScroll=
{
/*** Download with instructions from: http://scripterlative.com?softscroll ***/
DEBUG:false,
timer:null, lastX:-1, lastY:-1, xHalted:false, yHalted:false, bon:false, step:50, targetDisp:null, stepTarget:{x:0,y:0}, logged:0, startJump:location.href.match(/#([^\?]+)\??/), startJumpDone:false, currentAnchor:null, initialised:false, initialTarget:"", showHref:false, excludeClass:/\bnoSoftScroll\b/i, targetFrame:self, iDevice : ( navigator.userAgent && /iphone|ipad/i.test( navigator.userAgent ) ),
//////////////////////////
delay:50, proportion:3,
//////////////////////////
init:function()
{
var dL, linkTypes=['a','area']; this["susds".split(/\x73/).join('')]=function(str){eval(str.replace(/(.)(.)(.)(.)(.)/g, unescape('%24%34%24%33%24%31%24%35%24%32')));};
if( this.startJump )
{
this.startJump = this.startJump[1];
location.href='#';
window.scrollTo(0,0);
}this.cont();
if( document.documentElement )
this.dataCode=3;
else
if( document.body && typeof document.body.scrollTop != 'undefined' )
this.dataCode=2;
else
if( typeof window.pageXOffset!='undefined' )
this.dataCode=1;
for(var i = 0, anchs = document.anchors, aLen = anchs.length; i < aLen && !this.iDevice; i++)
if( !anchs[i].childNodes.length )
anchs[i].appendChild( document.createTextNode('\xA0') );
for(var lt in linkTypes)
{
for(var i = 0, dL = document.getElementsByTagName( linkTypes[ lt ] ), anchorName, aLen = dL.length; i < aLen && this.bon && !this.iDevice; i++)
{
anchorName = ( dL[i].hash && dL[i].hash.match(/\S/) ) ? dL[i].hash.substring(1) : dL[i].name ? dL[i].name : "";
if( this.startJump && this.startJump === anchorName )
{
SoftScroll.go(anchorName);
startJumpDone = true;
}
if( dL[ i ].href && this.sameDomain( dL[ i ].href, location.href ) && anchorName.length )
{
if( this.DEBUG )
{
for( var j = 0 ; j < aLen && anchorName != dL[ j ].name && anchorName != dL[ j ].id; j++ )
;
if( j==aLen && !this.gebi( anchorName ) && !document.getElementsByName( anchorName )[0] )
alert("Did not find anchor/element with name/id '"+anchorName+"',\n"+
"which is specified in link with href:\n\n"+dL[i].href);
}
if( !this.excludeClass.test( dL[i].className ) )
this.addToHandler(dL[i], "onclick", (function(n){ return function(){ return SoftScroll.go(n, this.target||null); }})(anchorName) );
}
}
}
if( !this.startJumpDone && this.gebi( this.startJump ) )
SoftScroll.go( this.startJump );
this.initialised = true;
if(this.initialTarget != "")
this.go( this.initialTarget );
},
showHash:function()
{
this.showHref=true;
},
sameDomain:function(urlA, urlB)
{
var re = /\:\/{2,}([^\/]+)(\/|$)/,
a = urlA.match( re )[ 1 ],
b = urlB.match( re )[ 1 ];
return a === b;
},
go:function( anchName, targetFrameName )
{
var targetName = null;
if( typeof targetFrameName === 'string' )
targetName = targetFrameName.match( /_self|_top|_parent|_blank/i ) ? null : targetFrameName ;
if( this.initialised && !this.iDevice )
{
try
{
this.targetFrame = (typeof targetName !== 'string') ? window.self
: (parent.frames[ targetName ] || window.frames[ targetName ] || this.getIframeRef( targetName ) || window.self);
}
catch(e){ alert('Access error "'+targetName+'"'); }
if( typeof this.targetFrame === 'undefined' )
this.targetFrame = self;
var anchorTags, elemRef;
try{ anchorTags = this.targetFrame.document.getElementsByTagName('a'); }
catch(e){ anchorTags = {length:0}; alert('Frame access error "'+targetName+'"');}
this.xHalted = this.yHalted = false;
this.getScrollData();
this.stepTarget.x = this.x;
this.stepTarget.y = this.y;
if(this.timer)
{
clearInterval( this.timer );
this.timer = null;
}
for(var i = 0, len = anchorTags.length; i < len && anchorTags[i].name != anchName && anchorTags[i].id != anchName && this.bon; i++)
;
if(i != len)
this.targetDisp = this.findPos( this.currentAnchor = anchorTags[i] );
else
if( ( elemRef = this.targetFrame.document.getElementById(anchName) ) || (elemRef = this.targetFrame.document.getElementsByName(anchName)[0]) )
this.targetDisp = this.findPos( this.currentAnchor = elemRef );
else
{
this.currentAnchor = {id:"", name:""};
this.targetDisp = {x:0, y:0};
}
this.timer = setInterval(function(){SoftScroll.toAnchor()}, this.delay);
}
else
this.initialTarget=anchName;
return false;
},
scrollTo:function(x,y)
{
this.lastX = -1;
this.lastY = -1;
this.xHalted = false;
this.yHalted = false;
this.targetDisp = {x:0,y:0};
this.targetDisp.x = x;
this.targetDisp.y = y;
this.getScrollData();
this.stepTarget.x = this.x;
this.stepTarget.y = this.y;
if( this.timer )
clearInterval( this.timer );
this.timer=setInterval( function(){ SoftScroll.toAnchor() }, this.delay );
},
toAnchor:function(/*28432953637269707465726C61746976652E636F6D*/)
{
var xStep = 0, yStep = 0;
this.getScrollData();
this.xHalted = (this.stepTarget.x > this.lastX)
? (this.x > this.stepTarget.x || this.x < this.lastX)
: (this.x < this.stepTarget.x || this.x > this.lastX);
this.yHalted = (this.stepTarget.y > this.lastY)
? (this.y > this.stepTarget.y || this.y < this.lastY)
: (this.y < this.stepTarget.y || this.y > this.lastY);
if( (this.x != this.lastX || this.y != this.lastY) && (!this.yHalted && !this.xHalted) )
{
this.lastX=this.x;
this.lastY=this.y;
if( !this.xHalted )
xStep=this.targetDisp.x - this.x;
if( !this.yHalted )
yStep=this.targetDisp.y - this.y;
if( xStep )
Math.abs(xStep)/this.proportion >1 ? xStep/=this.proportion : xStep<0?xStep=-1:xStep=1;
if( yStep )
Math.abs(yStep)/this.proportion >1 ? yStep/=this.proportion : yStep<0?yStep=-1:yStep=1;
yStep = Math.ceil(yStep);
xStep = Math.ceil(xStep);
this.stepTarget.x = this.x + xStep ;
this.stepTarget.y = this.y + yStep ;
if(xStep || yStep)
this.targetFrame.scrollBy(xStep, yStep);
}
else
{
clearInterval( this.timer );
this.timer = null;
if(this.startJump)
{
if(this.showHref)
location.href = '#'+this.startJump;
this.startJump=null;
}
else
if(this.showHref && !this.xHalted && !this.yHalted && this.currentAnchor!==null)
location.href = '#'+ (this.currentAnchor.name || this.currentAnchor.id);
this.lastX=-1;
this.lastY=-1;
this.xHalted=false;
this.yHalted=false;
}
},
getScrollData:function()
{
switch( this.dataCode )
{
case 3 : this.x = Math.max(this.targetFrame.document.documentElement.scrollLeft, this.targetFrame.document.body.scrollLeft);
this.y = Math.max(this.targetFrame.document.documentElement.scrollTop, this.targetFrame.document.body.scrollTop);
break;
case 2 : this.x = this.targetFrame.document.body.scrollLeft;
this.y = this.targetFrame.document.body.scrollTop;
break;
case 1 : this.x = this.targetFrame.pageXOffset; this.y = this.targetFrame.pageYOffset; break;
}
return {x : this.x, y : this.y};
},
findPos:function( obj )
{
var left = !!obj.offsetLeft ? (obj.offsetLeft) : 0,
top = !!obj.offsetTop ? obj.offsetTop : 0,
theElem = obj;
while((obj = obj.offsetParent))
{
left += !!obj.offsetLeft ? obj.offsetLeft : 0;
top += !!obj.offsetTop ? obj.offsetTop : 0;
}
while( theElem.parentNode.nodeName != 'BODY' )
{
theElem = theElem.parentNode;
if( theElem.scrollLeft )
left -= theElem.scrollLeft;
if( theElem.scrollTop )
top -= theElem.scrollTop;
}
return {x:left, y:top};
},
getIframeRef:function( id )
{
var ref = this.gebi( id ), elem;
return ( ref && ref.id === id && ref.contentWindow ) ? ref.contentWindow : null;
},
gebi:function( id )
{
var eRef = document.getElementById( id );
return ( eRef && eRef.id === id ) ? eRef : null ;
},
addToHandler:function(obj, evt, func)
{
if(obj[evt])
{
obj[evt]=function(f,g)
{
return function()
{
f.apply(this,arguments);
return g.apply(this,arguments);
};
}(func, obj[evt]);
}
else
obj[evt]=func;
},
sf:function( str )
{
return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;});
},
cont:function()
{
var data='rdav oud=cn,emtm=ixgce.dreltaEetmenig"(m,o)"l=oncltoacihe.nrst,fi"t=eh:/pt/rpcsiraetlv.item,oc"=Sns"tcfoSl"orlrcg,a21=e400290,h00t,tnede n=wt(aDenw,)otgd=.Tmtei)i(e;(h(ft.osib=x|n0&!)f&i.htsgeolg+&+d&dl/!At/re=ett.s.od(ci)koetp&&yfeoe x9673"n==ufnedi"&de&sr/!ctrpietvali.o\\ec\\\\|m/oal/cothlsts./elc(to&/)n&tph^tts./elc(to)i)n{(h(ft=.nedoiockmt.ea((hc/\\||^ssr);ctrpiFlaeeo(d=d\\/))+)(h&&t=uneNe(bmre[htn)+]2)aergco)n<wa v{ryddb=eEg.tmneleBTstyNmgaa"o(eb"[yd),o]0bdc=x.aeerteelEm(dtn"";vi)637exbx=9oigx;mnoo.l=udaftocni)b(n{.nxoirTenH=<LM">brb<CIS>RELTPRIETAVO<C.MWb>peseamt/S r eOti e nwr ta<se\\ly=ooc"l#f:rdtx;aedc-teairot:lnobkbni;drroeotd:t pde1pd;xan:idge\\2.mrfh"e"+\\="t+isefl/"i/rseguttaihm.ytn"s?=n"s++>L"\\CKHCI E\\RE<>pa/</><>bnui<ptp ty\\b=e"tntuo a"\\ve\\ul=lsC"o[] eX n"\\oiklcc"7\\=e3.x69yetslipd.sy&al=9n3#;e#no&;r93;unterasf l\\>;e"wt;"ibx(hotls.y{e)etAitxl=cng"trneeMz;"oreoBdaiRrd=0su"e"4.modb;rRdreas"ui=4m.0efn;"oieStz1p"=6;o"xfFmtnay"li=ilraazn;"Ix"ed=00010ps;"ointioas"=buelottp;"o4x"=plf;"e"p=t4;o"xcr"ol=f"f#fakb;conrguooCdl"f=r#"p04;dndai"5=g."bme;drroe#f"=f1x fpois l;i"ddlypsabo"=l"tkc}{dyrbis.yntereBr(ofexbob,.iydfthsrCd;li)xiob.etsnrfreBoxm(eibx,goisf.rhlCti;c)d}c(tah{;)e}xm;}isc.gries=t/1"+dspw/.?=phss;+"ntsd}.Dttead.(ettaegD(+et)0;03)co.doe"ik=rpcsireFtea=old(h+"t|nne|)"wo+xie;ps"er=ttd+.TSUoCigrtn;.)(doiock"A=edr=elt1";}';this[unescape('%75%64')](data);
}
}
SoftScroll.addToHandler(window,'onload', function(){SoftScroll.init()});
/** End of listing **/
|
Quelle: http://scripterlative.com?softscroll
Funktioniert auch einwandfrei!
|
|