[Pro] CAROUSEL/SMOOTH SCROLLER SCRIPT

I have designed a web page a with a carousel, that also has tabs and next/prev buttons.

On this page I have also placed ‘anchors’ at the bottom to take you back to the top and main (gallery) on the page, however these anchors used the smooth scroller script below by Dezinerfolio.

I paste in this HTML markup In the before head section as follows, but when I click on the carousel buttons they cause the page to scroll down to the anchors at the bottom of the page? Does this use a different Library that is not compatible with the ‘carousel’ action?

<script type="text/javascript">

/*--------------------------------------------------------------------------
 *  Smooth Scroller Script, version 1.0.1
 *  (c) 2007 Dezinerfolio Inc. <email@hidden>
 *
 *  For details, please check the website : http://dezinerfolio.com/
 *
/*--------------------------------------------------------------------------*/

Scroller = {
	// control the speed of the scroller.
	// dont change it here directly, please use Scroller.speed=50;
	speed:10,

	// returns the Y position of the div
	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},

	// returns the current scroll position
	scrollTop: function (){
		body=document.body
	    d=document.documentElement
	    if (body && body.scrollTop) return body.scrollTop
	    if (d && d.scrollTop) return d.scrollTop
	    if (window.pageYOffset) return window.pageYOffset
	    return 0
	},

	// attach an event for an element
	// (element, type, function)
	add: function(event, body, d) {
	    if (event.addEventListener) return event.addEventListener(body, d,false)
	    if (event.attachEvent) return event.attachEvent('on'+body, d)
	},

	// kill an event of an element
	end: function(e){
		if (window.event) {
			window.event.cancelBubble = true
			window.event.returnValue = false
      		return;
    	}
	    if (e.preventDefault && e.stopPropagation) {
	      e.preventDefault()
	      e.stopPropagation()
	    }
	},
	
	// move the scroll bar to the particular div.
	scroll: function(d){
		i = window.innerHeight || document.documentElement.clientHeight;
		h=document.body.scrollHeight;
		a = Scroller.scrollTop()
		if(d>a)
			if(h-d>i)
				a+=Math.ceil((d-a)/Scroller.speed)
			else
				a+=Math.ceil((d-a-(h-d))/Scroller.speed)
		else
			a = a+(d-a)/Scroller.speed;
		window.scrollTo(0,a)
	  	if(a==d || Scroller.offsetTop==a)clearInterval(Scroller.interval)
	  	Scroller.offsetTop=a
	},
	// initializer that adds the renderer to the onload function of the window
	init: function(){
		Scroller.add(window,'load', Scroller.render)
	},

	// this method extracts all the anchors and validates then as # and attaches the events.
	render: function(){
		a = document.getElementsByTagName('a');
		Scroller.end(this);
		window.onscroll
	    for (i=0;i<a.length;i++) {
	      l = a[i];
	      if(l.href && l.href.indexOf('#') != -1 && ((l.pathname==location.pathname) || ('/'+l.pathname==location.pathname)) ){
	      	Scroller.add(l,'click',Scroller.end)
	      		l.onclick = function(){
	      			Scroller.end(this);
		        	l=this.hash.substr(1);
		        	 a = document.getElementsByTagName('a');
				     for (i=0;i<a.length;i++) {
				     	if(a[i].name == l){
				     		clearInterval(Scroller.interval);
				     		Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(a[i])+')',10);
						}
					}
				}
	      	}
		}
	}
}
// invoke the initializer of the scroller
Scroller.init();


/*------------------------------------------------------------
 *						END OF CODE
/*-----------------------------------------------------------*/

</script>

I have also tried applying protaculious to the page, select scriptacilious-packed library and in the function body paste:

$$('a').each(function(elm){
    if(elm.href && $(elm.href.split(/#/).last())){
        elm.observe('click',function(evt){
            evt.stop();
            Effect.ScrollTo(elm.href.split(/#/).last());
        });
    }
});

This also has the same effect? I was wondering what the issue is, or if I have a bug?

The only work around atm is to remove the carousel buttons!

Any ideas guys would be great!

Worm


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Both of these smooth scroll functions work by “hooking” all anchor
links on the page, and applying a listener function to them to make
the smooth scroll behavior whenever they are clicked.

Carousel Button works exactly the same way, and one listener does not
cancel another listener, they just “stack” on top of each other. Try
excluding the smooth-scroll listener from any anchor that has the
classname ‘previous’ or ‘next’. Those are added by Carousel Button to
any anchor link that Action creates. Here’s how to do that:

$$('a:not(.previous):not(.next)').each(function(elm){
    if(elm.href && $(elm.href.split(/#/).last())){
        elm.observe('click',function(evt){
            evt.stop();
            Effect.ScrollTo(elm.href.split(/#/).last());
        });
    }
});

Let me know how that works for you.

Walter

On Aug 7, 2010, at 4:04 AM, Mr worm wrote:

The only work around atm is to remove the carousel buttons!

Any ideas guys would be great!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walt I tried adding the snippet of code to my page and it still didn’t work?!! The anchors at the bottom of the page now jump, and the carousel tabs cause the smooth slide to work, however only once. But the tabs and buttons then work ok!

Heres the page with your script:

http://www.edwardlawlor.co.uk/cc2010/gallerywalt.html

Heres the page with dezignerfolio script:

http://www.edwardlawlor.co.uk/cc2010/gallerydezinerfolio.html

Buttons don’t work, anchors do work,!!!

And here’s the page with the scriptacilious-packed library script:

http://www.edwardlawlor.co.uk/cc2010/galleryscript.html

Again anchors don’t work, and tabs cause scrolling to happen!!!??

What do you suggest Walt please?

Thank you BTW


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Try this one:

$$('a:not(.previous):not(.next)').each(function(elm){
	if(elm.href && $(elm.href.split(/#/).last()) && (! 
elm.up('div.controls'))){
		elm.observe('click',function(evt){
			evt.stop();
			Effect.ScrollTo(elm.href.split(/#/).last());
		});
	}
});

Hopefully this excludes all of the Carousel controls now.

Walter

On Aug 8, 2010, at 5:49 AM, Mr worm wrote:

Hi Walt I tried adding the snippet of code to my page and it still
didn’t work?!! The anchors at the bottom of the page now jump, and
the carousel tabs cause the smooth slide to work, however only once.
But the tabs and buttons then work ok!


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walt,

Sorry to be a pain, but everything works fine now except the smooth scroll effect on the anchors. The anchors work, but they jump to their location instead of scrolling!??

I’m only using the code in your last post on the page, I assume that is correct!

Do you need a live demo?

Worm


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The only thing that could be throwing this off is if these anchors point to nothing, like # or #top (if there’s nothing on the page with the ID ‘top’). Make sure you have an item at the top of your page that has an ID, and make your link to that, and this script will work.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options